Reputation: 3
first of all here is my code:
@protocol SearchTableViewControllerDelegate
@required
- (void)didSelectFileCardsContent:(FileCardsContent*)content;
@end
@interface SearchTableViewController : UITableViewController <UISearchBarDelegate, UISearchDisplayDelegate>{
id <SearchTableViewControllerDelegate> delegate;
...
}
@property (nonatomic, assign) id <SearchTableViewControllerDelegate> delegate;
...
@end
---------------------------------------------------
@implementation SearchTableViewController
@synthesize ... delegate;
...
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
FileCardsContent *fileCardToShow = [self.tableData objectAtIndex:indexPath.row];
[self.delegate didSelectFileCardsContent:fileCardToShow];
}
...
@end
---------------------------------------------------
@interface FileCardsViewCotroller : UIViewController <SearchTableViewControllerDelegate>{
...
@end
---------------------------------------------------
@implementation FileCardsViewCotroller
...
- (void)didSelectFileCardsContent:(FileCardsContent*)content{
[managedFileCards insertSingleContent:content];
self.currentFileCardsContent = content;
questionView1.text = currentFileCardsContent.question;
}
@end
My problem is - (void)didSelectFileCardsContent:(FileCardsContent*)content in FileCardsViewCotroller is never called. There are no compiler warnings or errors. I`m not familiar with protocols and delegates so is suggest there is a conceptually problem. Anny ideas?
Upvotes: 0
Views: 427
Reputation:
first it's good practice to check whether the method exists/is implemented by the delegate
if ([delegate respondsToSelector:@selector(didSelectFileCardsContent:)])
[delegate didSelectFileCardsContent:fileCardToShow];
don't use self.property when you're calling it in its own class. it executes unnecessary commands when you can just call it directly.
make sure you implemented the protocol in the delegate and implemented the method. make sure you set the delegate to self.
Upvotes: 1
Reputation: 18488
You just aren't assigning your delegate to anything so the message is sent to nil.
Upvotes: 0