我在Test1ViewController.m中推送test2ViewController,
Test2ViewController *test2ViewController = [[Test2ViewController alloc] initWithNibName:@"Test2ViewController" bundle:nil];
[self.navigationController pushViewController:test2ViewController animated:YES];
在Test2ViewController.m中,我插入了一个子视图test3ViewController,
Test3ViewController *test3ViewController = [[Test3ViewController alloc] initWithNibName:@"Test3ViewController" bundle:nil];
[self.view addSubview:test3ViewController.view];
我的问题,我想在test3ViewController中推送一个新视图(test4ViewController),但test3ViewController.view中的按钮操作不起作用
-(IBAction) goButtonAction:(id) sender {
Test4ViewController *test4ViewController = [[Test4ViewController alloc] initWithNibName:@"Test4ViewController" bundle:nil];
[self.navigationController pushViewController:test4ViewController animated:YES];
}
似乎test3ViewController不在导航流中,如何在插入视图上推送新视图?
答案 0 :(得分:0)
test3ViewController从未添加到navigationController的堆栈中。如果你想推送test4ViewController,那么你将不得不从test2ViewController执行它,或者使用UINavigationController的setViewControlers:animated:方法将test3ViewController添加到堆栈中:
NSMutableArray *array = [NSMutableArray arrayWithArray:test2ViewController.navigationController.viewControllers];
[array addObject:test3ViewController];
[test2ViewController.navigationController setViewControllers:array animated:NO];
[test2ViewController.navigationController popToViewController:test3ViewController animated:NO];