I want to call programmatically a segue
from the imagePickerController:didFinishPickingMediaWithInfo:
method, but it doesn't work. It doesn't crash, but doesn't work. It just does nothing. The prepareForSegue
method is called correctly.
- (void) imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info {
rutaFoto = [info valueForKey:UIImagePickerControllerMediaURL];
[self dismissModalViewControllerAnimated:YES];
[self performSegueWithIdentifier:@"aGaleria" sender:self];
}
The segue
links 2 UIViewControllers
. And if I call the segue with performSegueWithIdentifier
from other place (eg from a push UIButton
method), it works. 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).
[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.
I'd try two things, the first is to put a delay when you call the 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. You could set up a new NSNotificationCenter trigger in the original ViewController and then trigger it with a delay in the didFinishPicking method:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.