Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.98 KB | None | 0 0
  1. #import "AGViewController.h"
  2. #import "AGTaskObject.h"
  3. #import "AGTableViewCell.h"
  4.  
  5. //#import "AGSettingsViewController.h"
  6.  
  7.  
  8. @interface AGViewController ()
  9.  
  10. @end
  11.  
  12. @implementation AGViewController {
  13.  
  14. NSMutableArray *taskItems;
  15. }
  16.  
  17. -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
  18. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  19. if (self)
  20. {
  21. //Initializing the Array
  22. taskItems = [[NSMutableArray alloc] init];
  23.  
  24. [taskItems addObject:[AGTaskObject toDoItemWithText:@"Tap the + to add a Task"]];
  25. [taskItems addObject:[AGTaskObject toDoItemWithText:@"Tap the Gear Button to check out settings"]];
  26. [taskItems addObject:[AGTaskObject toDoItemWithText:@"Swipe Right to check off a task"]];
  27. [taskItems addObject:[AGTaskObject toDoItemWithText:@"Swipe Left to Delete a Task"]];
  28. [taskItems addObject:[AGTaskObject toDoItemWithText:@"I <3 Bacon"]];
  29. }
  30. return self;
  31. }
  32.  
  33. - (void)viewDidLoad
  34. {
  35. [super viewDidLoad];
  36.  
  37. //Table View Delegates
  38. self.tableView.delegate = self;
  39. self.tableView.dataSource = self;
  40.  
  41. //set the initial background image
  42. self.tableView.backgroundColor = [UIColor clearColor];
  43. self.backgroundImage.image = [UIImage imageNamed:@"blue.png"];
  44. [self.tableView registerClass:[AGTableViewCell class] forCellReuseIdentifier:@"cell"];
  45.  
  46. //Get rid of empty cells at bottom of tableview
  47. // self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
  48.  
  49. // Long Press Gesture to rearrange cells
  50. UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognized:)];
  51. [self.tableView addGestureRecognizer:longPress];
  52.  
  53. // // Tap Gesture to add a new cell
  54. // UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(<#selector#>)];
  55. }
  56.  
  57. - (void)didReceiveMemoryWarning
  58. {
  59. [super didReceiveMemoryWarning];
  60. // Dispose of any resources that can be recreated.
  61. }
  62.  
  63. #pragma mark - Button Press (IB)Actions
  64.  
  65. - (IBAction)settingsButtonPressed:(UIButton *)sender
  66. {
  67. [self performSegueWithIdentifier:@"toSettingsViewController" sender:nil];
  68. }
  69.  
  70. - (IBAction)addTaskButtonPressed:(UIButton *)sender
  71. {
  72. }
  73.  
  74. #pragma mark - UITableView Configuration
  75.  
  76. -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  77. {
  78. return [taskItems count];
  79. }
  80.  
  81. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  82. {
  83. NSString *cellIdentifier = @"cell";
  84. //re-Use or create a tableview cell
  85. AGTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier
  86. forIndexPath:indexPath];
  87. /* if (cell == nil) {
  88. cell = [[AGTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
  89. */
  90.  
  91. //Make the cells clear to show the background image
  92. cell.backgroundColor = [UIColor clearColor];
  93. //default font color will be white
  94. cell.textLabel.textColor = [UIColor whiteColor];
  95. //Set the task for each cell in the tableview
  96. AGTaskObject *item = taskItems[indexPath.row];
  97. //set the text
  98. cell.delegate = self;
  99. cell.taskObject = item;
  100.  
  101. // Recall final cell
  102. return cell;
  103. }
  104.  
  105. -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
  106. cell.backgroundColor = [self colorForIndex:indexPath.row];
  107. }
  108.  
  109. #pragma mark - TableItem Delete
  110.  
  111. -(void)toDoItemDeleted:(id)taskobject {
  112. // use the UITableView to animate the removal of this row
  113. NSUInteger index = [taskItems indexOfObject:taskobject];
  114. [self.tableView beginUpdates];
  115. [taskItems removeObject:taskobject];
  116. [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]]
  117. withRowAnimation:UITableViewRowAnimationFade];
  118. [self.tableView endUpdates];
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement