I have a big problem here. I wrote a custom UITableViewCell subclass completely customized with images and labels. I also created a custom action to edit the UITableView. When tapping the button, I am trying to perform an action to a UIButton which would, when tapped delete the cell. What I have works fine if I have one cell there. Here is what I have for the button to edit the table view.
// UINavigatinBarButton
Code:
- (void)editItems:(UIButton *)button {
if (!isEditing) {
NSLog(@"Editing...");
isEditing = YES;
[UIView beginAnimations:@"editButtonFlipContext" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:cell.checkmarkImage cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.3];
cell.checkmarkImage.image = [UIImage imageNamed:@"data_cell_delete_button.png"];
[UIView commitAnimations];
[cell.checkmarkButton addTarget:self action:@selector(deleteCell:event:) forControlEvents:UIControlEventTouchUpInside];
} else {
NSLog(@"Done Editing.");
isEditing = NO;
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(deleteCell:event:) object:nil];
[UIView beginAnimations:@"editButtonFlipContext" context:nil];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:cell.checkmarkImage cache:YES];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.3];
cell.checkmarkImage.image = [UIImage imageNamed:@"data_cell_detail_button.png"];
[UIView commitAnimations];
}
}
and for the UIButton in the cell:
// Cell Button
Code:
- (void)deleteCell:(id)sender event:(id)event {
NSSet *touches = [event allTouches];
UITouch *touch = [touches anyObject];
CGPoint currentTouchPosition = [touch locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint: currentTouchPosition];
if (indexPath != nil)
{
NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
[context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
}
}
It all seems to work fine on one cell like I said above, it won't make all the cells have that same action all the time, nor will it set the the correct image to it ("data_cell_delete_button.png"). If you need more info let me know. If you have any suggestions on fixing up the code for both actions I'd greatly appreciate it.
Thanks
Edit 2:
When clicking done on the navigation bar button, it doesn't remove the current @selector for the cell.checkmarkButton