NotificationCenter 常用函數
(1)addObserver函數 (訂閱消息)
void addObserver(Ref * target,SEL_CallFuncO selector,const std::string & name,Ref * sender)
根據指定的target,添加觀察者.
Ref * target :要訂閱消息的主體
SEL_CallFuncO selector :消息回調函數
std::string & name:消息名稱
Ref * sender :要傳遞的數據
(2)removeObserver 函數 (取消訂閱)
void removeObserver(Ref * target,const std::string & name)
根據指定的target 和 name 移除觀察者.
Ref * target:取消訂閱消息的主體
const std::string & name:消息名稱
(3)postNotification函數(發佈消息)
void postNotification(const std::string & name) 根據某個名字發送一個通知事件.
const std::string & name: 消息名稱
void postNotification(const std::string & name,Ref * sender) 根據某個名字發送一個通知事件.
const std::string & name: 消息名稱
Ref * sender: 要傳輸的數據
如果addObserver和postNotification函數都傳遞了數據,並且不是同一個數據,那將無法發佈消息。