In your case, when a cell is selected, you would:
- 创建下一个视图控制器的新实例,
- 将这个新实例推送到 UINavigationController 堆栈上。
因此,首先,您需要确保您的第一个视图控制器(带有表格视图的那个)包含在 UINavigationController 中。
// AppDelegate, in applicationDidFinishLanching:
UIViewController *firstViewController = [[[MyCustomTableViewController alloc]
initWithNibName:nil bundle:nil]
autorelease];
UINavigationController *navigationController = [[[UINavigationController alloc]
initWithRootViewController:firstViewController]
autorelease];
[self.window setRootViewController:navigationController];
然后,当您选择表格视图中的一个单元格时,您可以编写:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIViewController *nextViewController = [[[MyNextViewController alloc]
initWithNibName:nil bundle:nil]
autorelease];
[self.navigationController pushViewController:nextViewController
animated:YES]
}