从Detail Controller弹出到TableViewController

时间:2013-09-10 23:02:14

标签: ios objective-c uinavigationcontroller segue

我有一个ViewController1可以将推送进入ViewController2。反过来,这可以将推送到ViewController3。我在UIBarButtonItem中有一个ViewController1可以推送到ViewController3。但是,当我按下ViewController3中的后退按钮时,我需要弹出ViewController2

我该怎么做?这是我试过的代码:

ViewController2 *VC2 = [[ViewController2 alloc] init];
ViewController3 *VC3 = [[ViewController3 alloc] init];

[self.navigationController pushViewController:VC2 animated:NO];
[self.navigationController pushViewController:VC3 animated:YES];

2 个答案:

答案 0 :(得分:0)

试过你的解决方案,似乎对我有用, 但是,无论如何......如果由于任何原因它对你不起作用......试试这个:

NSArray *array = self.navigationController.viewControllers;
[self.navigationController setViewControllers:[array arrayByAddingObjectsFromArray:@[vc1,vc2]] animated:YES];

答案 1 :(得分:0)

根据@Camo的回答,这是我最终找到的内容。我通过ViewController3提出ViewController1。 Segue公司。然后,在ViewController3 viewDidLoad中,我输入了以下代码:

NSArray *array = self.navigationController.viewControllers;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
id TVC = [storyboard instantiateViewControllerWithIdentifier:@"VC2"];

[self.navigationController setViewControllers:[array arrayByAddingObjectsFromArray:@[TVC, self]] animated:NO];