objective-c – 未调用NSNotificationCenter选择器

objective-c – 未调用NSNotificationCenter选择器,第1张

概述在我的iPad应用程序中,在一个类中我注册了一个通知: NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(selectedList:) name:@"TTSelectedList" object:nil]; 我的selectedLi 在我的iPad应用程序中,在一个类中我注册了一个通知:
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选择器所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1237744.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-06
下一篇 2022-06-06

发表评论

登录后才能评论

评论列表(0条)

保存