objective-c - objective-c : Any issues in having 2 NSNotifications set up in a single class?

标签 objective-c ios nsnotifications

我有一个类实现了 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/

相关文章:

ios - 在 ios 中创建自定义进度指示器

c++ - 将回调从 C++ 转发到 ObjC

ios - 每5分钟获取后台位置更新一次

ios - swift : Upload pdf as "admin user" and send notification to other "normal users" that pdf is uploaded

iphone - 区分应用程序启动和应用程序唤醒

ios - 发送请求并获得响应

Objective-c:从另一个 Controller 调用 void 函数

ios - 用cocos2d插入时间延迟

iphone - 如何防止在 phone-gap 中运行的应用程序垂直滚动?

iphone - 防止 NSManagedObjectContextDidSaveNotification 事件重叠