Skip to content

Instantly share code, notes, and snippets.

@zmcartor
Created August 15, 2014 00:30
Show Gist options
  • Save zmcartor/73bcc143faa99af202b3 to your computer and use it in GitHub Desktop.
Save zmcartor/73bcc143faa99af202b3 to your computer and use it in GitHub Desktop.
Cocoa Responder Chain and UITableViews
// Whenever a button, tap , or something 'happens' within a cell subclass, send a message up thee olde Responder Chain
// -- within tablecell_subclass.m
- (IBAction)connectButtonClicked:(id)sender {
SEL selConnectButton = sel_registerName("connectButtonResponder:");
[[UIApplication sharedApplication] sendAction:selConnectButton to:nil from:self forEvent:nil];
}
// within the UITableViewController , responde to the selector "connectButtonResponder"
- (IBAction)connectButtonResponder:(id)sender {
NSAssert([sender class] == [tablecell_subclass class], @"something not expected was attached to connectButtonResponder: - you're a bad person");
UITableCell *cell = (UITableCell*)sender;
NSIndexPath *path = [self.tableView indexPathForCell:cell];
NSDictionary *someDatas = [self.datas objectAtIndex:path.row];
// .. do other things and respond to the event
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment