I am new to iPhone development, and I recently encounter a very strange problem with UITableController. I implemented a very simple program with UITableController where it has a datasource of an array of TestClass, where TestClass is a simple class I defined containing only a NSString attribute. The problem is that I can display the table, but when I select a cell and goes to didSelectRowAtIndexPath method, my datasource cannot be found anymore. And my program works well if I switch the datasource to an array of NSString instead of self-defined class. What's the problem of it?
- (id)initWithStyle:(UITableViewStyle)style {
if (self = [super initWithStyle:style]) {
self.title = @"TV Shows";
self.navigationItem.backBarButtonItem.title = @"Shows";
self.t = [NSArray arrayWithObjects:[[TestClass alloc] initWithTest:@"test"], nil];
}
return self;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
**NSLog(t); //NSException here**
TVAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.selectedShow = indexPath;
ShowCharactersTableViewController *showCharactersController = [[ShowCharactersTableViewController alloc开发者_Go百科] initWithStyle:UITableViewStylePlain];
[[delegate navigationController] pushViewController:showCharactersController animated:YES];
[showCharactersController release];
}
Try:
NSLog(@"%@",t);
It will print the description of the t object. t is not a litteral string, so it can't be logged directly, you have to use a format. (Didn't you get a warning?)
精彩评论