performSegueWithIdentifier not working

删除回忆录丶 提交于 2019-11-30 15:59:00

I'm assuming that the view you are trying to segue to is using the picture you get just before you do your segue? If they cancel from the image picker do you still want to segue?

If it needs the picture, then maybe you should call your segue after the delegate call "did finish picking".

The issue with the segue not firing may be due to the animation still occurring from here:

[[picker presentingViewController] dismissModalViewControllerAnimated:YES];

You can try:

[[picker presentingViewController] dismissModalViewControllerAnimated:NO];

or if you want to maintain the animation, move the segue to the "picker did finish" method and do it this way:

[self dismissModalViewControllerAnimated:YES completion:^() {
[self performSegueWithIdentifier:@"lastView" sender:self];
}];

or if that does not work try this approach in the pickerdidfinish method (note - this should be implemented as a delegate in the controller that calls the modal view, not the modal view itself:

//maintain the animation
[self dismissModalViewControllerAnimated:YES];

//slight pause to let the modal page dismiss and then start the segue
double delayInSeconds = 0.5;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){

    //code to be executed on the main queue after delay

    [self performSegueWithIdentifier:@"lastView" sender:self];

});

I use this transition frequently and it makes a nice drop away with the modal view then slides in the segue view and the pause allows the transition to seem natural.

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