我设置了一个只有两个按钮的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);
}
}我应该忽略这个构建警告吗?或者我如何纠正这个警告?
发布于 2011-03-28 06:27:32
您需要在头文件中以@interface开头的行的花括号({)之前添加<UIActionSheetDelegate>。例如:
@interface MyViewController : UIViewController <UIActionSheetDelegate> {这将消除该警告。
发布于 2011-03-28 06:28:42
你的错误意味着你没有实现UIActionSheetDelegate协议。要做到这一点,你必须像这样在你的接口中实现它:
@interface MyViewController : UIViewController <UIActionSheetDelegate> {
}UIActionSheetDelegate协议不需要方法,这就是你的应用不会崩溃的原因。
https://stackoverflow.com/questions/5452852
复制相似问题