我有两个 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/