UIImagePickerController dismissModalViewController
- by Deepak Sharma
I am trying to invoke UIImagePickerController to select a movie on iPhone 3GS and when the movie is selected, i just dismiss it and present MyViewController modally with a configured delay of 1.0 seconds. What I notice is 10% of the times, presentModalViewController on MyViewController does nothing whereas it works 90% of the times. I want to understand why is this behavior and what is the remedy. Here is the sample code:
(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSURL *videoURL = nil;
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:@"public.movie"])
{
videoURL = [info objectForKey:UIImagePickerControllerMediaURL];
}
picker.delegate = nil;
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
[self performSelector:@selector(launchMyViewController:) withObject:nil
afterDelay:1.0];
}
-(void) launchMyViewController:(id) obj
{
MyViewController *myCtrl = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:[NSBundle mainBundle] controller:self];
[self presentModalViewController:myCtrl animated:YES];
[myCtrl release];
NSLog(NSStringFromClass([self.modalViewController class]));
[path release];
}
I have put NSLog statement to print the self.modalViewController class name and what I notice is that 10% of the times when myCtrl is not fired modally, the self.modalViewController.class is UIImagePickerController. Otherwise, the self.modalViewController.class is MyViewController. I want to know why is the behavior so unpredictable and what is the workaround or other way to achieve the same thing I intend.