我有一个HomeViewController.m,我在其中按 self.navigationController
推送SpecificViewController,
SpecificViewController *specificViewController= [[SpecificViewController alloc] initWithNibName:@"SpecificViewController" bundle:nil];
[self.navigationController pushViewController:specificViewController animated:YES];
在SpecificViewController.m中,我插入一个子视图
FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
[self.view insertSubview:firstViewController.view atIndex:0];
在FirstViewController.m中,有一个tableview . 问题是如何通过navigationController推送一个新的ViewController,我在下面尝试,但它不起作用 .
-(void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailTableViewController *detail =
[[DetailTableViewController alloc] initWithStyle:UITableViewStyleGrouped];
[self.navigationController pushViewController:detail animated:YES];
[detail release];
[self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
我还是尝试了一个新的UINavigationController,
UINavigationController *NEWnavigationController;
NEWnavigationController=[[UINavigationController alloc] init];
[NEWnavigationController pushViewController:detail animated:YES];
但它仍然无效 . 你能给我任何建议吗?
1 回答
你的方法有很多问题 .
首先,是您加载的第一个视图控制器的SpecificViewController?如果是,则不要推送此视图控制器,而是将其设置为应用程序委托中的根视图控制器,如下所示
这将确保您的Navigation控制器已设置,并且出现的第一个视图控制器是SpecificViewController
其次,您不要将视图控制器作为子视图插入 . 如果您尝试加载第二个视图控制器,则将其推送到导航控制器堆栈 . 您可以从SpecificViewController执行此操作,如下所示