我有一個問題,即:不叫(委託設置爲self)的UIImagePickerController委託方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {}
只能被稱爲用相機,而不是當我試圖通過用戶的瀏覽照片,選擇一個圖像。
這裏是爲UIImagePicker代表我的初始化代碼:
-(void)viewDidLoad{
[self initImagePicker];
}
-(void)initImagePicker{
DLog(@"");
self.imagePickerController.delegate = self;
}
- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType
{
self.imagePickerController.sourceType = sourceType;
if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
// user wants to use the camera interface
//
self.imagePickerController.showsCameraControls = NO;
if ([[self.imagePickerController.cameraOverlayView subviews] count] == 0)
{
// setup our custom overlay view for the camera
//
// ensure that our custom view's frame fits within the parent frame
CGRect overlayViewFrame = self.imagePickerController.cameraOverlayView.frame;
CGRect newFrame = CGRectMake(0.0,CGRectGetHeight(overlayViewFrame)-15.0,CGRectGetWidth(overlayViewFrame),15.0);
self.view.frame = newFrame;
[self.imagePickerController.cameraOverlayView addSubview:self.view];
[self.view bringSubviewToFront:self.view];
}
}
}
然後在我的根類,一來就是授人以類UIImagePicker是委託給UIImagePicker:
#pragma mark -
#pragma mark Toolbar Actions
- (void)showImagePicker:(UIImagePickerControllerSourceType)sourceType
{
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
// camera is not on this device, don't show the camera button
NSMutableArray *toolbarItems = [NSMutableArray arrayWithCapacity:self.myToolbar.items.count];
[toolbarItems addObjectsFromArray:self.myToolbar.items];
[toolbarItems removeObjectAtIndex:2];
[self.myToolbar setItems:toolbarItems animated:NO];
}
if ([UIImagePickerController isSourceTypeAvailable:sourceType])
{
self.overlayViewController = [[UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil] instantiateViewControllerWithIdentifier:@"OverlayViewController"];
self.overlayViewController.delegate = self;
self.overlayViewController.imagePickerController = [[UIImagePickerController alloc] init];
[self.overlayViewController setupImagePicker:sourceType];
[self presentModalViewController:self.overlayViewController.imagePickerController animated:YES];
}
}
我知道這是一個SO問題的很多代碼,但對於實現這個類的經驗豐富的人來說,我做錯了什麼?
對我來說,這條線是奇怪的:
self.overlayViewController.imagePickerController = [[UIImagePickerController alloc] init];
我從來沒有分配和初始化前的所有者以外的財產。這是問題嗎?
從哪裏調用'setupImagePicker'和'showImagePicker' – 2013-02-17 12:05:23
在調用showImagePicker時出現的UIImagePicker委託視圖控制器中調用setUpImagePicker。 – stackOverFlew 2013-02-17 12:07:14