简体   繁体   中英

Why is there a compiler warning on this statement?

In a standard iPhone app I'm displaying an image picker on top of a table view. The code works fine (I believe ;-)), but I get a compiler warning when setting the image picker delegate to be the table view controller (ChoiceController).
在此处输入图片说明 ChoiceController is defined to implement the delegate:

@interface ChoiceController : UITableViewController <UIActionSheetDelegate, UIImagePickerControllerDelegate, MFMailComposeViewControllerDelegate> and clearly does become the delegate, because it receives all the appropriate actions.

I've tried casting ChoiceController, ie self, to UIImagePickerControllerDelegate but I get the same result.

Insights welcomed!

You can see in the warning text that the delegate has to be UIImagePickerControllerDelegate , but also UINavigationControllerDelegate .

It's defined so: @property (nonatomic, assign) id<UINavigationControllerDelegate, UIImagePickerControllerDelegate> delegate

In your case, it works fine because all UINavigationControllerDelegate methods are optional. Had that not been the case, the app would have crashed with unknown selector send to instance exception.

You should implement the UINavigationControllerDelegate protocol. If you do not need any of the methods declared there, and they are indeed optional, do not implement them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM