Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #import "AGViewController.h"
- #import "AGTaskObject.h"
- #import "AGTableViewCell.h"
- //#import "AGSettingsViewController.h"
- @interface AGViewController ()
- @end
- @implementation AGViewController {
- NSMutableArray *taskItems;
- }
- -(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self)
- {
- //Initializing the Array
- taskItems = [[NSMutableArray alloc] init];
- [taskItems addObject:[AGTaskObject toDoItemWithText:@"Tap the + to add a Task"]];
- [taskItems addObject:[AGTaskObject toDoItemWithText:@"Tap the Gear Button to check out settings"]];
- [taskItems addObject:[AGTaskObject toDoItemWithText:@"Swipe Right to check off a task"]];
- [taskItems addObject:[AGTaskObject toDoItemWithText:@"Swipe Left to Delete a Task"]];
- [taskItems addObject:[AGTaskObject toDoItemWithText:@"I <3 Bacon"]];
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- //Table View Delegates
- self.tableView.delegate = self;
- self.tableView.dataSource = self;
- //set the initial background image
- self.tableView.backgroundColor = [UIColor clearColor];
- self.backgroundImage.image = [UIImage imageNamed:@"blue.png"];
- [self.tableView registerClass:[AGTableViewCell class] forCellReuseIdentifier:@"cell"];
- //Get rid of empty cells at bottom of tableview
- // self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
- // Long Press Gesture to rearrange cells
- UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressGestureRecognized:)];
- [self.tableView addGestureRecognizer:longPress];
- // // Tap Gesture to add a new cell
- // UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(<#selector#>)];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - Button Press (IB)Actions
- - (IBAction)settingsButtonPressed:(UIButton *)sender
- {
- [self performSegueWithIdentifier:@"toSettingsViewController" sender:nil];
- }
- - (IBAction)addTaskButtonPressed:(UIButton *)sender
- {
- }
- #pragma mark - UITableView Configuration
- -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- return [taskItems count];
- }
- -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSString *cellIdentifier = @"cell";
- //re-Use or create a tableview cell
- AGTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier
- forIndexPath:indexPath];
- /* if (cell == nil) {
- cell = [[AGTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
- */
- //Make the cells clear to show the background image
- cell.backgroundColor = [UIColor clearColor];
- //default font color will be white
- cell.textLabel.textColor = [UIColor whiteColor];
- //Set the task for each cell in the tableview
- AGTaskObject *item = taskItems[indexPath.row];
- //set the text
- cell.delegate = self;
- cell.taskObject = item;
- // Recall final cell
- return cell;
- }
- -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
- cell.backgroundColor = [self colorForIndex:indexPath.row];
- }
- #pragma mark - TableItem Delete
- -(void)toDoItemDeleted:(id)taskobject {
- // use the UITableView to animate the removal of this row
- NSUInteger index = [taskItems indexOfObject:taskobject];
- [self.tableView beginUpdates];
- [taskItems removeObject:taskobject];
- [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:index inSection:0]]
- withRowAnimation:UITableViewRowAnimationFade];
- [self.tableView endUpdates];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement