我有一个导航控制器A,我在其上推动视图控制器B.从B i模态显示视图控制器C.我需要同时关闭C和弹出B.我想按顺序,首先保持解散动画,然后将流行动画从B保持到A.我尝试了这段代码没有成功:
[self dismissViewControllerAnimated:YES completion:^{
[self.presentingViewController.navigationController popViewControllerAnimated:YES];
}];
关于如何实现这一目标的任何建议?
答案 0 :(得分:1)
如果您在C视图控制器中编写,则:
UIViewController *pvc = self.presentingViewController;
UINavigationController *navController = [pvc isKindOfClass:[UINavigationController class]] ? (UINavigationController *)pvc : pvc.navigationController;
[self dismissViewControllerAnimated:YES completion:^{
[navController popViewControllerAnimated:YES];
}];
或者如果在B视图控制器中
[self.presentedViewController dismissViewControllerAnimated:YES completion:^{
[self.navigationController popViewControllerAnimated:YES];
}];
答案 1 :(得分:1)
我曾尝试连续弹跳两次,但没有解雇一个并弹出另一个。你可以尝试我做的,看看它是否适合你。
在子视图B中:
- (void)subViewCController:(SubViewCController *)controller didSelectID:(NSNumber *)theID
{
// do something with theID...
// for my case, I popped
// [self.navigationController popViewControllerAnimated:YES];
// for your case
[self dismissViewControllerAnimated:YES completion:nil];
// Somehow, adding a small delay works for me and the animation is just nice
[self performSelector:@selector(backToSubViewA) withObject:nil afterDelay:0.6];
}
- (void)backToSubViewA
{
[self.navigationController popViewControllerAnimated:YES];
}
答案 2 :(得分:0)
您使用的是故事板和赛段吗?如果是这样,你可以使用unwind segue:
在您的第一个视图控制器(您要跳回到的那个,而不是从返回的那个)中,创建一个展开segue动作:
- (IBAction)gotoMainMenu:(UIStoryboardSegue *)segue
{
// if you need to do anything when you return to the main menu, do it here
}
然后在故事板中,您可以创建一个来自" dismiss"按钮到场景上方栏中的退出插座图标(),您将看到那里列出的main menu
。