Skip to content

Instantly share code, notes, and snippets.

@acf
Created September 19, 2009 07:38
Show Gist options
  • Save acf/189432 to your computer and use it in GitHub Desktop.
Save acf/189432 to your computer and use it in GitHub Desktop.
@interface MyCellController : NibBasedCellController {
Class _controllerClass;
GithubAccount* _githubAccount;
}
@end
// Would be nice to make some assertions about newControllerClass
// (must be a UIViewController that conforms to protocol GitHubAccountAware
- (id) initWithControllerClass:(Class)newControllerClass account:(GithubAccount*)account {
if( self = [super initWithNibName:@"MyCell" bundle:nil] ) {
self.githubAccount = account;
_controllerClass = newControllerClass;
}
return self;
}
//So that instead of all the respondsToSelector malarkey to keep the compiler happy
//like here
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewController *tableViewController = (UITableViewController *)tableView.dataSource;
NSObject* controller = [[[_controllerClass alloc] init] autorelease];
if( [controller respondsToSelector:@selector(setAccount:)] ) {
[controller performSelector:@selector(setAccount:) withObject:self.githubAccount];
}
[tableViewController.navigationController pushViewController:(UIViewController*)controller animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
//I could safely do this.
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewController *tableViewController = (UITableViewController *)tableView.dataSource;
UIViewController<GithubAccountAware>* controller = [[[_controllerClass alloc] init] autorelease];
controller setAccount = self.githubAccount;
[tableViewController.navigationController pushViewController:controller animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment