NSNotificationCenter簡單使用

2021-08-27 01:55:21 字數 600 閱讀 7895

作用:nsnotificationcenter是專門供程式中不同類間的訊息通訊而設定的.

註冊通知:即要在什麼地方接受訊息

[[nsnotificationcenter defaultcenter]  addobserver:self selector:@selector(mytest:) 

name:@" mytest" 

object:nil

];引數介紹:

addobserver: 觀察者,即在什麼地方接收通知;

selector: 收到通知後呼叫何種方法;

name: 通知的名字,也是通知的唯一標示,編譯器就通過這個找到通知的。

傳送通知:呼叫觀察者處的方法。

[[nsnotificationcenter

defaultcenter] postnotificationname:@"mytest" object:searchfriendarray];

引數:postnotificationname:通知的名字,也是通知的唯一標示,編譯器就通過這個找到通知的。

object:傳遞的引數

NSNotificationCenter 用法詳解

作用 nsnotificationcenter是專門供程式中不同類間的訊息通訊而設定的.註冊通知 即要在什麼地方接受訊息 nsnotificationcenter defaultcenter addobserver self selector selector 方法名稱 name 唯一標示 obje...

NSNotificationCenter 程式設計簡介

1.註冊通知 即要在什麼地方接受訊息 要註冊接收通知的函式以及傳遞的物件,訊息名稱 nsnotificationcenter defaultcenter addobserver self selector selector mytest name mytest object nil 引數介紹 add...

NSNotificationCenter 深入使用

通知傳送,一般我們會使用 nsnotificationcenter defaultcenter addobserver self selector selector mytest name mytest object nil 然後在任意地方使用 nsnotificationcenter defaul...