无法调用imagePickerControllerDidCancel

时间:2014-05-30 00:51:03

标签: uibutton uiimagepickercontroller

我使用uiimagepickercontroller拍照并设置overlayview,有一个取消uiimagepickercontroller的按钮

UIButton *btnCancel = [UIButton buttonWithType:UIButtonTypeCustom];
btnCancel.frame = CGRectMake(20, 50, 20, 20);
[btnCancel setImage:[UIImage imageNamed:@"cancel.png"] forState:UIControlStateNormal];
[btnCancel addTarget:self action:@selector(cancelshoot) forControlEvents:UIControlEventTouchUpInside];
[overlay addSubview:btnCancel];

- (void)cancelshoot
{
  NSLog(@"cancel");
  [self.imagePickerController dismissViewControllerAnimated:YES completion:nil];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
  NSLog(@"can this be called?");
  [picker dismissViewControllerAnimated:YES completion:nil];
}
单击取消按钮后无法调用imagePickerControllerDidCancel,只打印日志'取消',我该如何解决?

2 个答案:

答案 0 :(得分:1)

您创建的按钮已连接到cancelshoot方法,因此正确地发生了正确的事情。在那时解雇选择器取决于你。

imagePickerControllerDidCancel:委托方法适用于用户点击选择器的内置取消按钮的情况。 Cocoa不知道你的按钮是一个取消按钮 - 你调用它的事实"取消"它的标题在某种程度上并不神奇。

请注意,在iPad上,选择器是弹出式窗口,没有“取消”按钮,因此imagePickerControllerDidCancel: 从不调用。

答案 1 :(得分:0)

实现pickerDelegate使用选择器来解除它的自我

- (void)imagePickerControllerDidCancel:(ImagePickerController *)picker {
    [picker dismissViewControllerAnimated:YES completion:^{
        //
    }];
}