[英]Call performSegueWithIdentifier from didFinishPickingMediaWithInfo
I want to call programmatically a segue
from the imagePickerController:didFinishPickingMediaWithInfo:
method, but it doesn't work. 我想以编程方式从
imagePickerController:didFinishPickingMediaWithInfo:
方法中调用segue
,但是它不起作用。 It doesn't crash, but doesn't work. 它不会崩溃,但是不起作用。 It just does nothing.
它什么也没做。 The
prepareForSegue
method is called correctly. prepareForSegue
方法被正确调用。
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
rutaFoto = [info valueForKey:UIImagePickerControllerMediaURL];
[self dismissModalViewControllerAnimated:YES];
[self performSegueWithIdentifier:@"aGaleria" sender:self];
}
The segue
links 2 UIViewControllers
. segue
链接2个UIViewControllers
。 And if I call the segue with performSegueWithIdentifier
from other place (eg from a push UIButton
method), it works. 而且,如果我从其他地方(例如,从push
UIButton
方法)使用performSegueWithIdentifier
调用segue,它就可以工作。 Any ideas? 有任何想法吗?
Try using dismissViewControllerAnimated:completion: and put the call to performSegueWithIdentifier:sender: in the completion block (dismissModalViewControllerAnimated: is depreciated anyway, so you shouldn't be using it). 尝试使用dismissViewControllerAnimated:completion :,并将对performSegueWithIdentifier:sender:的调用放在完成块中(dismissModalViewControllerAnimated:无论如何都已贬值,因此您不应该使用它)。
[self dismissViewControllerAnimated:YES completion:^{
[self performSegueWithIdentifier:@"aGaleria" sender:self];
}];
I'm wondering if this is to do with the main thread already handling a change in the current ViewController, the transition between didFinishPickingMediaWithInfo to the original ViewController from which it was triggered from. 我想知道这是否与已经在当前ViewController中进行了更改的主线程有关,即didFinishPickingMediaWithInfo与触发它的原始ViewController之间的过渡。
I'd try two things, the first is to put a delay when you call the aGaleria segue: 我会尝试两件事,第一件事是延迟致电aGaleria segue的时间:
sleep(2.0);
[self performSegueWithIdentifier:@"aGaleria" sender:self];
The second, and much better option, is to perform the segue from the view AFTER you have finishedPickingMediaWithInfo. 第二种也是更好的选择,是在完成PickingMediaWithInfo之后从视图执行segue。 You could set up a new NSNotificationCenter trigger in the original ViewController and then trigger it with a delay in the didFinishPicking method:
您可以在原始ViewController中设置新的NSNotificationCenter触发器,然后在didFinishPicking方法中延迟地触发它:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.