我有一个类实现了 2 个 NSNotifications
//Set up notifications
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(getData)
name:@"Answer Submitted"
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadTable)
name:@"Comment Submitted"
object:nil];
我只是想检查一下是否可以在一个类中设置 2 个观察者?另外,当我删除观察者时,我仅在 dealloc 方法中删除一个观察者。这是一个问题吗?
最佳答案
在一个类中拥有多个观察者是完全可以的。使用完观察者后,您应该始终取消注册它。
有关 Objective-C 中观察者模式的更多详细信息,请参见 here .
关于objective-c - objective-c : Any issues in having 2 NSNotifications set up in a single class?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6470646/