2011-03-27 35 views
0

我已经设置了一个UIActionSheet弹出只有两个按钮,并为其中的一个分配了一个动作。该应用程序编译和运行和正常工作,但我得到警告:UIActionSheetDelegate警告视图控制器

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); 

} 

} 

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

回答

3

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

@interface MyViewController : UIViewController <UIActionSheetDelegate> { 

这将压制警告。

1

你的错误意味着你没有实现UIActionSheetDelegate协议。要做到这一点,你必须实现它在你的界面那样:

@interface MyViewController : UIViewController <UIActionSheetDelegate> { 
} 

并不需要的UIActionSheetDelegate协议的方法,这就是为什么你的应用程序不死机。

相关问题