识别UIImagePickerController代理中的不同选择器 [英] Identifying different pickers in UIImagePickerController delegate

查看:119
本文介绍了识别UIImagePickerController代理中的不同选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个视图,有几个按钮,我用来呈现UIImagePickerController(相机和媒体选择器)。当我创建UIImagePickerController时,我给他们不同的名字,并给出它们的模态,如下面的代码所示:

   - ( void)startMediaBrowserFromViewControllerForBGImage {
UIImagePickerController * mediaUIForBGImage = [[UIImagePickerController alloc] init];
//我也在这里设置了一堆不同的设置,但这并不重要
mediaUIForBGImage.delegate = self;
[self presentModalViewController:mediaUIForBGImage animated:YES];
}

现在,您还可以在代码中看到,我将委托设置为 self ,这就是我所做的所有的UIImagePickerController,但问题是 - 在委托方法中,我如何知道哪个UIImagePickerController称为委托方法。因为每个UIImagePickerControllers需要采取的媒体行动是不同的。在委托方法中,我得到 UIImagePickerController 参数,但它始终具有从方法(选择器)分配的名称。我可以使用哪些UIImagePickerController来引用?

解决方案

我想你可以存储对每个选择器的引用,然后检查如果是同一个实例。虽然我会质疑使用多个不同的选择器实例,但是您可以配置一个单一的实例吗?此外,它们在任何配置中返回几乎相同的结果,您可以针对特定需求调查结果字典。

  self.oneImagePicker = [UIImagePickerController ...] 
self.twoImagePicker = [UIImagePickerController ...]

//在委托
if([self.oneImagePicker isEqual:picker])...


I have a view with a couple of buttons whick I use to present UIImagePickerControllers (both camera and media pickers). When I create the UIImagePickerControllers, I give them diffrent names and present them modaly as you can see in the code below:

- (void) startMediaBrowserFromViewControllerForBGImage {
    UIImagePickerController * mediaUIForBGImage = [[UIImagePickerController alloc]init];
    //i also set a bunch of different settings here, but it doesn't matter for this purpose
    mediaUIForBGImage.delegate = self;
    [self presentModalViewController: mediaUIForBGImage animated:YES];
}

Now as you can also see in the code, I set the delegate to self, and that is what I do with all the UIImagePickerControllers, but the problem is - in the delegate methods, how do I know which UIImagePickerController called the delegate method. Because the actions I need to take with the media is different for each UIImagePickerControllers. In the delegate method I do get the UIImagePickerController parameter, but it always have the name that it is assigned from the methods (picker). What can I use to know which UIImagePickerController to refer to?

解决方案

I think you can store a reference to each picker and then check if it is the same instance. Though I would question using multiple different picker instances, can you just configure a single one? Also they return pretty much the same results in any configuration, you can investigate result dictionary for specific needs.

self.oneImagePicker = [UIImagePickerController ...]
self.twoImagePicker = [UIImagePickerController ...]

//In delegate
if ([self.oneImagePicker isEqual:picker]) ...

这篇关于识别UIImagePickerController代理中的不同选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆