2016-10-01 100 views
1

我已經設置以下選項,同時使用iPad的圖像。問題是委託人似乎永遠不會被調用。我已經放置了斷點,但它們從未激活過。IOS 10 UIImagePickerController委託沒有被調用

.H

@interface HomeViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate> 

.M

- (IBAction)loadImage:(id)sender { 

self.imagePickerController = [[UIImagePickerController alloc] init]; 
self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext; 
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; 
self.imagePickerController.allowsEditing = NO; 
self.imagePickerController.delegate = self; 

[self presentViewController:self.imagePickerController animated:YES completion:nil]; 

} 

// This method is called when an image has been chosen from the library or taken from the camera. 
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 
{ 

//You can retrieve the actual UIImage 
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage]; 
//Or you can get the image url from AssetsLibrary 
NSURL *path = [info valueForKey:UIImagePickerControllerReferenceURL]; 

[picker dismissViewControllerAnimated:YES completion:nil]; 
} 

任何人都可以看到這個問題?

感謝

+0

看到這一次http://stackoverflow.com/questions/38236723/ios-10-error-access-private-when-using-uiimagepickercontroller –

+0

我沒有複製和粘貼你的代碼,你寫在新的示例項目中我創建,但它的作品。我沒有描述過的一件事就是info.plist隱私照片庫的使用。 – boraseoksoon

+0

嗨,檢查了info.plist,並且隱私設置已經存在。真的很奇怪,因爲我似乎無法找到問題。 – ORStudios

回答

1

如果使用Xcode8運行項目,請檢查項目的Info.plist,確保有對「隱私照片庫的使用」一鍵。

你的代碼是正確的,也許問題是info.plist。

+0

嗨,那已經在那裏,原來是一個錯誤,因爲重新啓動Ipad後,它一切正常。 – ORStudios

0

我有一個類似的問題,事實證明,挑選圖像被選中後,垃圾回收,所以委託沒有被調用。

我需要確保在呈現之前對拾取器進行了強有力的引用。

一旦完成,它工作正常。

相關問題