Skip to content

Instantly share code, notes, and snippets.

@mikeabdullah
Last active August 29, 2015 14:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeabdullah/4026898e96860a03a8c3 to your computer and use it in GitHub Desktop.
Save mikeabdullah/4026898e96860a03a8c3 to your computer and use it in GitHub Desktop.
Connecting cell to controller using a block
@interface MyTableViewCell
@property(nonatomic, copy) void (^checkboxHandler)(void);
@end
@implementation MyTableViewCell
- (IBAction)checkboxPressed:(UIButton *)sender {
self.checkboxHandler();
}
@end
@implementation MyTableViewController
- (UITableViewCell *)tableView:(UITableView *)table cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyTableViewCell *cell = [table dequeueReusableCellWithIdentifier:@"cell"
forIndexPath:indexPath;
cell.checkboxHandler = ^{
// Perform the desired work in response to checkbox
};
return cell;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment