UIActionSheetDelegate Warning for View Controller
I've set up a UIActionSheet popup with just two buttons and assigned an action to one of them. The app compiles and runs and works properly but I get the warning:
warning: class 'MyViewController' does not implement the 'UIActionSheetDelegate' protocol
Here is my action sheet code:
- (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];
And the action I signed to the "Save Image" button:
-(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);
}
}
Should I ignore this build warning? Or how can I rectify the warning?
You need to add <UIActionSheetDelegate>
just before the curly bracket ({
) on the line which starts with @interface
in the header file. Eg:
@interface MyViewController : UIViewController <UIActionSheetDelegate> {
This will squash the warning.
You error means you don't have implement the UIActionSheetDelegate protocol. To do that, you have to implement it in your interface like that :
@interface MyViewController : UIViewController <UIActionSheetDelegate> {
}
The UIActionSheetDelegate protocol doesn't required methods, that's why your app don't crash.
精彩评论