iPhone中的NSNotification [英] NSNotification in iphone

查看:47
本文介绍了iPhone中的NSNotification的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将NSSNotifcation发送到iPhone应用程序中的另一个视图控制器,但是它的观察者方法收到两次通知,一个人怎么可能指导我

i am sending NSSNotifcation to another view controller in iPhone app but its observer method getting notified two times how its possible can any one guide me

我已使用此代码发布通知

i have use this code to post notification

[[NSNotificationCenter defaultCenter] postNotificationName:@"updateStatusOnFacebook" object:nil userInfo:nil];

并添加了观察者

[[NSNotificationCenter defaultCenter]   addObserver:self  selector:@selector(postToWall)                name:@"updateStatusOnFacebook"  object:nil];

推荐答案

您是否两次添加了观察者?

Have you added the observer twice?

您要在哪个方法中调用addObserver:selector:object :?如果它在viewWillAppear中,则可能会多次调用.

Which method are you calling addObserver:selector:object: in? If it's in viewWillAppear then this might be called more than once.

您的方法将被调用与您添加观察者相同的次数.

Your method will be called the same number of times that you have added an observer.

尝试一下:

[[NSNotificationCenter defaultCenter] removeObserver:self name:@"updateStatusOnFacebook" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(postToWall) name:@"updateStatusOnFacebook" object:nil];


另一个原因是您可能只发送了两次通知:)


The other reason is that you might just be sending the notification twice :)

这篇关于iPhone中的NSNotification的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆