我为此花了几个小时,并尝试了各种方法。我可以确认 didSelectRowAtIndexPath 确实正在运行,并且正在返回我正在寻找的特定对象。
没有做任何事情的部分是我试图显示 SensDetailViewClass 视图的部分。它运行代码,但是 SensDetailViewClass.m 中的 viewDidLoad 方法没有运行,视图也没有改变。
我想显示 SensDetailViewClass。我可以确认 .xib 文件的所有者是 SensDetailsViewClass。
请帮忙。这是代码。
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// get the selected item
Sens *info = [_sensInfos objectAtIndex:indexPath.row];
// initialise the detail view controller and display it
SensDetailViewClass *details = [[SensDetailViewClass alloc] initWithNibName:@"MainWindow" bundle:nil];
// set the title of the page
[details setTitle:info.heading];
details.selectedSens = info;
[self.navigationController pushViewController:details animated:YES];
[details release];
}
更新:我通过使用这种机制让它工作:[self presentModalViewController:details animated:YES];