NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addobserver:self selector:@selector(selectedList:) name:@"TTSelectedList" object:nil];
我的selectedList:方法如下所示:
- (voID)selectedList:(NSNotification*)notification{ NSLog(@"received notification");}
然后在另一个类(UItableVIEwController)中,我在选择行时发布该通知:
- (voID)tableVIEw:(UItableVIEw *)tableVIEw dIDSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"posting notification"); [[NSNotificationCenter defaultCenter] postNotificationname:@"TTSelectedList" object:nil];}
我可以确认通知正在发布,因为“发布通知”被记录到控制台,但是从未调用“已接收通知”,这意味着未收到通知且未调用选择器.我无法弄清楚造成这种情况的原因.
谢谢
解决方法 最可能的原因是你实际上并没有调用addobserver:selector:name:object:.你那里没有伐木线;你确定代码正在运行吗?第二个最可能的原因是您在发布通知之前调用了removeObserver:这最常见于dealloc(如果您曾经观察过任何内容,则应始终调用removeObserver).这里的错误是你的观察对象在通知之前已经解除分配.
总结以上是内存溢出为你收集整理的objective-c – 未调用NSNotificationCenter选择器全部内容,希望文章能够帮你解决objective-c – 未调用NSNotificationCenter选择器所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)