Dismissviewcontroller并执行segue

时间:2012-12-05 22:01:47

标签: objective-c ios uiviewcontroller segue

我需要使用performSegueWithIdentifier转到另一个viewcontroller,但我还需要删除我当前所在的viewcontroller。我怎么能这样做,我试过这个但它不起作用:

[self performSegueWithIdentifier:@"next" sender:self];
[self dismissViewControllerAnimated:NO completion:nil];

//tried the other way, but it doesn't work either
[self dismissViewControllerAnimated:NO completion:nil];
[self performSegueWithIdentifier:@"next" sender:self];

看起来没有简单的方法可以做到这一点? 我有4个视图控制器,它们是这样连接的,我想从游戏切换到高分。

menu-->game----->gameover
menu-->highscore

4 个答案:

答案 0 :(得分:6)

这个怎么样?

UIViewController *parentController = self.presentingViewController;
[picker dismissViewControllerAnimated:YES completion:^(void){
    [parentController performSegueWithIdentifier:@"next" sender:self];
}];

答案 1 :(得分:1)

我遇到了同样的问题,如果有人来这里寻找答案,这就是我要解决的问题。

//In viewController that is being dismissed
[self dismissViewControllerAnimated:NO completion:^{
     [[NSNotificationCenter defaultCenter] postNotificationName:@"callSegue" object:self];
}];


//In viewController being presented
//in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver: self
                                             selector: @selector(gotoNewView)
                                                 name: @"callSegue"
                                               object: nil];

-(void)gotoNewView {
    [self performSegueWithIdentifier:@"segueToPerform" sender:self];
}

答案 2 :(得分:0)

我遇到了同样的问题,直到我意识到我应该使用push segue。
新VC将立即解雇他们。

答案 3 :(得分:0)

更好:

[self dismissViewControllerAnimated:NO completion:^(void)
{
 // Perform the segue here.
}];
相关问题