UIImagepicker会立即在iPhone上消失

时间:2013-12-20 14:23:03

标签: ios iphone ipad uiimagepickercontroller

我有2个适用于iPhone和iPad的故事板。 从UITableviewcontroller上的Button我想选择一个带有UIImagepicker的图像。

在iPad上运行正常,在iPhone上UIImagepicker显示的时间很短,然后他就消失了。

对于iPad和iPhone,调用代码是相同的,我可以看到故事板是同一性的。我正在寻找几个小时,看不出为什么Imagepicker会在iPhone和iPad上消失。 有没有人对这种行为有所了解? UIImagePicker在没有做任何事情的情况下消失的原因是什么?


- (void) go {
    UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
    [ipc setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
    ipc.delegate=self;
    [self presentViewController:ipc animated:YES completion:^{}];
    }
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    NSLog(@"imagePickerControllerDidCancel");
    [self dismissViewControllerAnimated:YES completion:^{}];
    }

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    [self.navigationController dismissViewControllerAnimated:NO completion:^{}];
    [self dismissViewControllerAnimated:NO completion:^{}];
        NSLog(@"didFinishPickingMediaWithInfo");
    }

在iPhone上,日志“imagePickerControllerDidCancel”永远不会显示!

1 个答案:

答案 0 :(得分:0)

将选择器存储在强类属性中而不是局部变量中,如下所示:

@property(nonatomic, strong) UIImagePickerController *imagePickerController

...

- (void) go {
    self.imagePickercontroller = [[UIImagePickerController alloc]init];
    self.imagePickercontroller.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    self.imagePickercontroller.delegate=self;
    [self presentViewController:ipc animated:YES completion:nil];
}