弹出根目录,然后在iPhone上执行序列 [英] Pop to root then perform segue on iPhone
问题描述
我正在iOS 6.0情节提要板上运行
I am running on iOS 6.0 storyboard enabled
我有一个链接到TableViewController的NavController.这个TableView可以选择AViewController或BViewController.
I have a NavController linked to a TableViewController. This TableView can segue to AViewController or BViewController.
当我在A中时,我想弹出到根目录,并使用此行对B执行segue:
When I am in A, I want to pop back to the root and perform segue to B with this line :
UINavigationController *nav = self.navigationController;
[nav popToRootViewControllerAnimated:YES];
[nav performSegueWithIdentifier:@"GoToB" sender:self];
我检查了情节提要,GoToB确实存在并且从TableViewController链接到BViewController
I checked the storyboard, GoToB do exist and is linked from the TableViewController to BViewController
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<NavMainViewController: 0xb921fa0>) has no segue with identifier 'GoToB''
我想念什么?
推荐答案
segue将附加到您弹出的视图控制器,而不是包含在其中的容器视图控制器 nav
.因此,这将更加接近:
The segue will be attached to the view controller you pop to, not nav
which is the container view controller that contains it. So this would be closer:
UINavigationController *nav = self.navigationController;
[nav popToRootViewControllerAnimated:YES];
UIViewController *rootVC = [nav.viewControllers objectAtIndex:0];
[rootVC performSegueWithIdentifier:@"GoToB" sender:self];
但是,我认为这里的问题将是流行动画将与segue冲突.使用... Animated:NO进行弹出可能会解决它,但我认为从rootVC执行segue会更正确(对于动画来说更健壮).
But, I think the problem here will be that the pop animation will conflict with the segue. Doing the pop with ...Animated:NO might fix it, but I think it would be more correct (and more robust for animations) to perform the segue from the rootVC.
rootVC将按如下方式实现viewDidAppear:
rootVC would implement viewDidAppear as follows:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if (!self.isBeingPresented && /* any other condition that makes you want this */) {
[self performSegueWithIdentifier:@"GoToB" sender:self];
}
}
这篇关于弹出根目录,然后在iPhone上执行序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!