我可以从其他班级观看NSNotification吗? [英] Can I watch an NSNotification from another class?
问题描述
我正试着绕过NSNotificationCenter。如果我的App Delegate中有类似的内容:
I'm trying to get my head around NSNotificationCenter. If I have something like this in my App Delegate:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(something:)
name:@"something"
object:nil];
-----
-(void)something:(NSNotification *) notification
{
// do something
}
我可以在另一个视图控制器中以某种方式观察这个吗?在我的情况下,我想在带有表的视图控制器中观察它,然后在收到通知时重新加载表。这可能吗?
Can I somehow watch this in another view controller? In my case, I'd like to watch it in a view controller with a table, and then reload the table when a notification is received. Is this possible?
推荐答案
是的,你可以这就是 NSNotification $ c $的全部目的c>,你只需要像在App Delegate上那样添加你想要的观察者,它就会收到通知。
Yes you can that is the whole purpose of NSNotification
, you just have to add the View Controller you want as an observer exactly the same way you did on your App Delegate, and it will receive the notification.
你可在此处找到更多信息:通知编程
You can find more information here: Notification Programming
这篇关于我可以从其他班级观看NSNotification吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!