UIImagePickerController dismissModalViewController

时间:2010-04-17 14:00:01

标签: iphone uiimagepickercontroller

我正在尝试调用UIImagePickerController来选择iPhone 3GS上的电影,当选择电影时,我只是将其解除并以模态方式呈现MyViewController,配置延迟为1.0秒。我注意到的是10%的时间,MyViewController上的presentModalViewController什么都不做,而它的工作时间是90%。我想了解为什么这种行为以及解决方法是什么。以下是示例代码:

  • (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];

}

我已经把NSLog语句打印出self.modalViewController类名,我注意到myCtrl没有以模态方式触发的时间是10%,self.modalViewController.class是UIImagePickerController。否则,self.modalViewController.class是MyViewController。我想知道为什么这种行为如此不可预测,以及解决方法或其他方式来达到我想要的目的。

1 个答案:

答案 0 :(得分:0)

我猜测使用performSelector:afterDelay:调用是个问题。尝试立即调用您的启动方法,而不是延迟。