识别UIImagePickerController代理中的不同选择器 [英] Identifying different pickers in UIImagePickerController delegate
问题描述
- ( 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屋!