按下 actionSheet 按钮后的警告消息 [英] Warning message after actionSheet buttons are pressed

查看:23
本文介绍了按下 actionSheet 按钮后的警告消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 iOS 开发非常陌生,遇到了一个我似乎无法找到解决方案的错误.我到处寻找解决方案,但也许是我的新事物阻止了我看到问题.

I am very new to iOS development and have encountered an error that I just can't seem to find a solution for. I have searched for solutions everywhere, but maybe it is my newness that is preventing me from seeing the problem.

打印在日志中的确切警告是:

The exact warning that is printed in the log is:

在演示或关闭正在进行时尝试从视图控制器 <_UIAlertShimPresentingViewController: 0x7aaa4b90> 关闭!

它在我触摸 actionSheet 上的按钮后立即发生.

It occurs right after I touch a button on the actionSheet.

代码如下:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

    if (buttonIndex == 0) {

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;

        [self presentViewController:picker animated:YES completion:nil];
    }
    else if (buttonIndex == 1) {

        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentViewController:picker animated:YES completion:nil];

    }
    else if (buttonIndex == 2) {
        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

        [self presentViewController:picker animated:YES completion:nil];

    }

} else {

    if (buttonIndex == 0) {

        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;


        [self presentViewController:picker animated:NO completion:NULL];


    }
    else if (buttonIndex == 1) {

        picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

        [self presentViewController:picker animated:YES completion:NULL];


    }


}
}

actionSheet 的实现,我将 IBAction 连接到一个位于 .xib 文件的工具栏按钮.

The implementation of the actionSheet, I have the IBAction connected a toolbar button located an the .xib file.

   - (IBAction)addImage:(id)sender {

UIActionSheet *popUpSheet = [[UIActionSheet alloc]
                             initWithTitle:nil
                             delegate:self
                             cancelButtonTitle:nil
                             destructiveButtonTitle:nil
                             otherButtonTitles: nil];

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

    [popUpSheet addButtonWithTitle:@"Camera"];
    [popUpSheet addButtonWithTitle:@"Photo Library"];
    [popUpSheet addButtonWithTitle:@"Camera Roll"];

    [popUpSheet addButtonWithTitle:@"Cancel"];

    popUpSheet.cancelButtonIndex = popUpSheet.numberOfButtons-1;

}   else {

    [popUpSheet addButtonWithTitle:@"Photo Library"];
    [popUpSheet addButtonWithTitle:@"Camera Roll"];

    [popUpSheet addButtonWithTitle:@"Cancel"];

    popUpSheet.cancelButtonIndex = popUpSheet.numberOfButtons-1;

}

[popUpSheet showFromBarButtonItem: self.toolbarItems[0] animated:YES];  }

据我所知,一切都已正确委派:

Everything has been delegated correctly from what I can tell:

DetailViewController.m

DetailViewController.m

@interface DetailViewController () < UINavigationControllerDelegate, UIImagePickerControllerDelegate >

DetailViewController.h

DetailViewController.h

@interface DetailViewController : UIViewController <UIActionSheetDelegate>

任何见解都将不胜感激并且非常有帮助.

Any insight would be greatly appreciated and extremely helpful.

推荐答案

您的代码看起来正确.尝试使用:

Your code looks correct. Try using the:

actionSheet:didDismissWithButtonIndex:

方法.它在动画结束后发送给委托.希望有帮助.

method. It's sent to the delegate after the animation ends. Hope it helps.

这篇关于按下 actionSheet 按钮后的警告消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆