Search code examples
objective-cioscocoa-touchdelegation

Delegate after subclassing?


I'm sorry, i was not able to formulate a short question for the title..

In case i subclass a class with a delegate protocol and property, does my delegate still need to implement the delegate protocol of the superclass, or do i have to define a new one for the subclass?

In my case I subclassed UIImagePickerController:

[(UIImagePickerController *)self.myUIImagePickerControllerSubclassInstance setDelegate:self];

When I try to set its delegate to self, from some view controller I get the following warning:

warning: Semantic Issue: Sending 'ViewController *' to parameter of incompatible type 'id'


Solution

  • Your delegate needs to comply with UIImagePickerController property declaration:

    @property (nonatomic, assign) id<UINavigationControllerDelegate, UIImagePickerControllerDelegate> delegate

    So, try adding <UIImagePickerControllerDelegate> to your subclass interface:

    @interface YourPicker : UIImagePickerController <UIImagePickerControllerDelegate>
    ...
    @end
    

    And probably you'll need UINavigationControllerDelegate and implement mandatory methods, if any.