Say, I want to call a UIActionSheet from a helper class method. I want the helper class (not the object) to be the delegate of this actionsheet. So I'm passing self to the delegate.
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"MyTitle"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:@"Delete"
otherButtonTitles:nil];
My helper class implements the delegate methods as class methods and everything works fine. But, I get a warning from the compiler that says, Incompatible pointer, sending Class when id is expected. I also tried [self class] and getting the same warning.
How can I avoid this warning?
Just set the delegate to [self self]
.
You can get rid of the warning by casting self to type id.
[[UIActionSheet alloc] initWithTitle:@"MyTitle"
delegate:(id<UIActionSheetDelegate>)self
cancelButtonTitle:nil
destructiveButtonTitle:@"Delete"
otherButtonTitles:nil];
This will tell the compiler to treat the value as an id
which conforms to the UIActionSheetDelegate protocol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With