gpt4 book ai didi

iphone - 未调用 UIImagePickerController 委托(delegate)方法(委托(delegate)设置为自身)

转载 作者:可可西里 更新时间:2023-11-01 06:25:04 26 4
gpt4 key购买 nike

我有一个问题:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {}

仅在使用相机时调用,而不是在我尝试通过浏览用户的照片来选择图像时调用。

这是我的 UIImagePicker 委托(delegate)的初始化代码:

-(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 的委托(delegate)是 UIImagePicker 的委托(delegate):

#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];

我以前从未在所有者之外分配和初始化过属性。是这个问题吗?

最佳答案

我认为您过早地设置了委托(delegate)(viewDidLoad 中的initImagePicker)。 self.imagePickerController 可能是零。您应该在创建 UIImagePickerController 之后设置委托(delegate)。

关于iphone - 未调用 UIImagePickerController 委托(delegate)方法(委托(delegate)设置为自身),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14920731/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com