ios如何在使用后解除UIImagePickerController

时间:2012-03-14 14:32:24

标签: ios uiimagepickercontroller

我开发了一个应用程序,从相机unitl拍摄照片这里所有很好的蝙蝠收到他的代表我解雇,我收到exc_bad_access这里是代码:

声明并打开相机:

-(void)ScattaFoto{
 UIImagePickerController *picke = [[UIImagePickerController alloc] init];
   // Delegate is self
   picke.delegate = self;

    // Allow editing of image ?
picke.allowsEditing=NO;


if(TARGET_IPHONE_SIMULATOR) {
      picke.sourceType =  UIImagePickerControllerSourceTypePhotoLibrary;
     }else{
    picke.sourceType =  UIImagePickerControllerSourceTypeCamera;
    }

   // Show image picker
[self presentModalViewController:picke animated:YES];   

}

而不是委托事件:

- (void) imagePickerController:(UIImagePickerController *)picke   didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Access the uncropped image from info dictionary
//UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

// [picker release];
[self  dismissModalViewControllerAnimated: YES]; // Here i receive exc_bad_access
[picke release];
}

我把.h引用了imagePickerControl的委托“UINavigationControllerDelegate,UIImagePickerControllerDelegate”

有人可以帮助我吗?

3 个答案:

答案 0 :(得分:3)

- (void) imagePickerController:(UIImagePickerController *)picke didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [picke  dismissModalViewControllerAnimated: YES];
}

答案 1 :(得分:1)

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
       [picker.presentingViewController dismissViewControllerAnimated:YES completion:nil];

}

答案 2 :(得分:0)

也许ARC在调用didFinishPickingMediaWithInfo之前发布你的UIImagePickerController?

尝试将UIImagePickerController放在@property中,如下所示:

@property (nonatomic, strong) UIImagePickerController *picke;

You can read more about @properties here.

在使用之前,你仍然需要分配和初始化UIImagePickerController。