Dismissviewcontroller and perform segue

泄露秘密 提交于 2019-12-12 11:22:33

问题


I need to go to another viewcontroller with performSegueWithIdentifier but I also need to remove the viewcontroller I'm currently in. How can I do this, I have tried this but it doesn't work:

[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];

It looks like there isn't any easy way to do this? I have 4 viewcontrollers, they are connected like this, and I want to go from gameover to highscore.

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

回答1:


How about this?

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



回答2:


I had the same problem, this is what I did to resolve if anyone comes here looking for answers.

//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];
}



回答3:


I had the same problem until I realized I should use a push segue instead.
The New VC will dismiss them both at once.




回答4:


Even better:

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


来源:https://stackoverflow.com/questions/13733263/dismissviewcontroller-and-perform-segue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!