Created
September 19, 2009 07:38
-
-
Save acf/189432 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
@interface MyCellController : NibBasedCellController { | |
Class _controllerClass; | |
GithubAccount* _githubAccount; | |
} | |
@end |
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
// 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