NSNotificationCenter 傳遞帶參數的通知


NSNotificationCenter  在  init里面注冊這個通知,

NSString* const str = @"FuckMe";

   [[NSNotificationCenter defaultCenteraddObserver:self selector:@selector(on:)   name:str object:nil];

在dealloc里面移除這個通知的注冊: 

   [[NSNotificationCenter  defaultCenterremoveObserver:self  name:str object:nil];

以上為不帶參數的通知

 

一般在使用NSNotificationCenter的時候不使用參數,但是有些時候需要使用參數。

傳遞參數

[[NSNotificationCenter defaultCenter] postNotificationName:@"test" object:searchFriendArray];

接收參數並獲取傳遞的參數

 

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

object:傳遞的參數

 

- (void) test:(NSNotification*) notification

{

    searchFriendArrary = [notification object];//通過這個獲取到傳遞的對象


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM