[英]delegate method never called
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. 我的问题是-永远不会调用FileCardsViewCotroller中的(void)didSelectFileCardsContent:(FileCardsContent *)content。 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?
有想法吗?
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. 在自己的类中调用self.property时不要使用它。 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.
确保将委托设置为self。
您只是没有将您的委托分配给任何东西,因此消息被发送到nil。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.