【问题标题】:UIActionSheetDelegate Warning for View Controller视图控制器的 UIActionSheetDelegate 警告
【发布时间】:2011-07-24 02:19:13
【问题描述】:

我设置了一个只有两个按钮的 UIActionSheet 弹出窗口,并为其中一个按钮分配了一个动作。该应用程序编译并运行并正常工作,但我收到警告:

warning: class 'MyViewController' does not implement the 'UIActionSheetDelegate' protocol

这是我的操作表代码:

- (IBAction)saveImage {


    UIActionSheet *saveMenu = [[UIActionSheet alloc] initWithTitle:@"Save Image to Photo Library" 
                                                          delegate:self 
                                                 cancelButtonTitle:@"Dismiss" 
                                            destructiveButtonTitle:nil 
                                                 otherButtonTitles:@"Save Image", nil];

    [saveMenu showInView:self.view];
    [saveMenu release];

还有我在“保存图片”按钮上签名的操作:

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

if (buttonIndex == 0) {

    UIImage* imageToSave = [imageView image]; // alternatively, imageView.image

    //Save it to the camera roll / saved photo album
    UIImageWriteToSavedPhotosAlbum(imageToSave, nil, nil, nil);

}

}

我应该忽略这个构建警告吗?或者我该如何纠正警告?

【问题讨论】:

    标签: iphone objective-c cocoa-touch xcode ios4


    【解决方案1】:

    您需要在头文件中以@interface 开头的行的大括号({)之前添加<UIActionSheetDelegate>。例如:

    @interface MyViewController : UIViewController <UIActionSheetDelegate> {
    

    这将消除警告。

    【讨论】:

      【解决方案2】:

      您的错误意味着您没有实现 UIActionSheetDelegate 协议。为此,您必须像这样在界面中实现它:

      @interface MyViewController : UIViewController <UIActionSheetDelegate> {
      }
      

      UIActionSheetDelegate 协议不需要方法,这就是您的应用不会崩溃的原因。

      【讨论】:

        猜你喜欢
        • 2017-01-27
        • 2015-07-16
        • 1970-01-01
        • 2013-11-22
        • 1970-01-01
        • 2011-08-18
        • 2018-01-03
        • 1970-01-01
        • 2012-08-28
        相关资源
        最近更新 更多