Created
August 6, 2018 16:37
-
-
Save sean7218/42415b06ae2e5b2c766f445c3ede3812 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { | |
static NSString *CellIdentifier = @"Cell"; | |
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; | |
if (cell == nil) { | |
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; | |
} | |
if ([selectedRowsArray containsObject:[contentArray objectAtIndex:indexPath.row]]) { | |
cell.imageView.image = [UIImage imageNamed:@"checked.png"]; | |
} | |
else { | |
cell.imageView.image = [UIImage imageNamed:@"unchecked.png"]; | |
} | |
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleChecking:)]; | |
[cell.imageView addGestureRecognizer:tap]; | |
cell.imageView.userInteractionEnabled = YES; //added based on @John 's comment | |
//[tap release]; | |
cell.textLabel.text = [contentArray objectAtIndex:indexPath.row]; | |
return cell; | |
} | |
- (void) handleChecking:(UITapGestureRecognizer *)tapRecognizer { | |
CGPoint tapLocation = [tapRecognizer locationInView:self.tableView]; | |
NSIndexPath *tappedIndexPath = [self.tableView indexPathForRowAtPoint:tapLocation]; | |
if ([selectedRowsArray containsObject:[contentArray objectAtIndex:tappedIndexPath.row]]) { | |
[selectedRowsArray removeObject:[contentArray objectAtIndex:tappedIndexPath.row]]; | |
} | |
else { | |
[selectedRowsArray addObject:[contentArray objectAtIndex:tappedIndexPath.row]]; | |
} | |
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:tappedIndexPath] withRowAnimation: UITableViewRowAnimationFade]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment