我是 iPhone 开发新手,最近遇到了一个很奇怪的 UITableController 问题。我用 UITableController 实现了一个非常简单的程序,它有一个 TestClass 数组的数据源,其中 TestClass 是我定义的一个简单的类,它只包含一个 NSString 属性。问题是我可以显示表格,但是当我选择一个单元格并转到 didSelectRowAtIndexPath 方法时,我的数据源再也找不到了。如果我将数据源切换到 NSString 数组而不是自定义类,我的程序运行良好。它有什么问题?
- (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] initWithStyle:UITableViewStylePlain];
[[delegate navigationController] pushViewController:showCharactersController animated:YES];
[showCharactersController release];
}