I have a problem with Objective-C protocols.
I have defined protocol:
@protocol PlayerProfileSectionProReviewDelegate <NSObject>
- (void)didReceivedPlayerProfileSectionProReviewData;
@end
@interface PlayerProfileSectionProReviewModel : PlayerProfileSectionModel
@property (weak) id <PlayerProfileSectionProReviewDelegate> playerProfileSectionProReviewDelegate;
@end
In this class implementation I call delegate:
if ([self.playerProfileSectionProReviewDelegate respondsToSelector:@selector(didReceivedPlayerProfileSectionProReviewData)])
{
[self.playerProfileSectionProReviewDelegate didReceivedPlayerProfileSectionProReviewData];
}
In view controller I have added PlayerProfileSectionProReviewDelegate and overriden didReceivedPlayerProfileSectionProReviewData method:
@interface PlayerProfileSectionProReviewViewController : PlayerProfileSectionViewController <UITableViewDelegate, UITableViewDataSource, PlayerProfileSectionProReviewDelegate>
@end
and
#pragma mark <PlayerProfileSectionProReviewDelegate>
- (void)didReceivedPlayerProfileSectionProReviewData
{
[self.playerProReviewTableView reloadData];
}
Why my protocol does not respond to selector?
Somewhere in your
PlayerProfileSectionProReviewViewControllerclass implementation, you need to set the appropriatePlayerProfileSectionProReviewModelobject's delegate, like this:If you do this, then when
myModelreaches your delegate call, your view controller will receive it.By the way, you can simplify these lines:
With:
At this point if the delegate is
nil, no message will be sent and you won't get any runtime error.