如何避免UIImagePickerController选择照片时多次点击会多次触发代理方法

最近测试报出来,当双击选择照片时,就会触发2次点击事件,调查发现确实触发了2次代理方法,

原代码

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // 业务处理逻辑
    [self doSomeWorking];

    picker.delegate = nil;
    [picker dismissViewControllerAnimated:YES completion:nil];
    
}

解决方法如下

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    // 先将代理置空,防止触发多次。
    picker.delegate = nil;
    [picker dismissViewControllerAnimated:YES completion:nil];

    // 业务处理逻辑
    [self doSomeWorking];
}

你可能感兴趣的:(如何避免UIImagePickerController选择照片时多次点击会多次触发代理方法)