开发者

UIImagePickerController dismissModalViewController

开发者 https://www.devze.com 2022-12-27 10:55 出处:网络
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 seco

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 开发者_JS百科thing I intend.


I'm going to guess that using the performSelector:afterDelay: call is the problem. Try calling your launch method immediately, instead of through the delay.

0

精彩评论

暂无评论...
验证码 换一张
取 消