ios - 如何区分didFinishPickingMediaWithInfo中的UIImagePickerController

标签 ios objective-c uiimagepickercontroller picker

我有两个 UIImageViews,我想在其中加载两个不同的图像。我有两个按钮触发 UIImagePickerController 并调用我的

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

方法。

有没有办法区分上面的方法调用的是哪个picker?

最佳答案

你可以创建一个 UIButton 的实例

@interface YourClass ()
{
   UIButton *_selectedButton;
}

并且在触发UIImagePickerController之前,可以将按钮保存在实例变量中

-(void)button1Clicked:(UIButton *)button1{
      _selectedButton = button1;
     // call UIImagePickerController
} 

-(void)button2Clicked:(UIButton *)button2{
      _selectedButton = button2;
      // call UIImagePickerController
} 


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{   
      if (_selectedButton == button1){
         // perform your logic 
      } else if (_selectedButton == button2){
        // perform your logic 
      }
}

关于ios - 如何区分didFinishPickingMediaWithInfo中的UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33389234/

相关文章:

objective-c - CTLineRef 是否拥有属性字符串?

iphone - 使用 UIImagePickerController 以特定分辨率捕获照片

ios - 关闭相机并返回应用程序需要很长时间

jquery - $(document).on 点击​​处理程序和标准点击处理程序在 iOS 上的行为不同

iphone - uiview 在 ios7 中出现失真,但适用于 ios6 和其他

ios - UITextField - 开头和结尾的不可编辑前缀字符

iphone - 如何在 iphone 应用程序中解析 HTML 页面数据?

ios 7 图像选择器在 popover 中的错误行为

ios - UITableViewCell 中的 UIStackView 具有多行 UILabels

ios - 转换二维数组