Я использую UIImagePickerView
в своем коде, в котором есть три кнопки. Один для съемки, второй - для выбора фотографии и третий для отмены. Код, как указано ниже:Кнопка отмены не работает в UIImagePickerView
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select the operation to proceed?"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Take Photo", @"Select Photo", nil];
[actionSheet showInView:self.view];
Когда я нажимаю кнопку «Отмена», она не работает.
Я использую метод UIImagePickerViewDelegate
, как показано ниже.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
@try {
//set selected image in imageview by imagepickerview
UIImage *chosenImage = info[UIImagePickerControllerEditedImage];
imgProfilePic.image = chosenImage;
[picker dismissViewControllerAnimated:YES completion:nil];
}
@catch (NSException *exception) {
NSLog(@"%@",exception.description);
}
}
//- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
//{
// NSLog(@"@@@@");
// [picker dismissViewControllerAnimated:YES completion:NULL];
//}
Пожалуйста, проверьте мой код UIImagePickerView
и предоставить мне указания для правильного кода.
#pragma mark - Actionssheet delegate method for Image
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
@try {
if(buttonIndex != 3)
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
if(buttonIndex == 0)
{
NSLog(@"Choose Photo from Camera");
//simulator has no camera so app will crash, below call just provide the alert that device has no camera.
if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Error"
message:@"Device has no camera"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[myAlertView show];
}
else
{
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
}
if(buttonIndex == 1)
{
NSLog(@"Choose Photo from Gallary");
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}
// if (buttonIndex == 3)
// {
// NSLog(@"###");
// }
//
// else
// {
// NSLog(@"Cancel the tab");
// [picker dismissViewControllerAnimated:YES completion:NULL];
//
// }
[self presentViewController:picker animated:YES completion:nil];
}
}
@catch (NSException *exception) {
NSLog(@"%@",exception.description);
}
}
Вы работаете прошивка 9 или прошивка 8 – Chetan
Отмены кнопки для чего? – user3182143
При нажатии кнопки отмены, она закрывает вид действия листа – user3182143