IOS學習 postNotificationName 消息傳遞詳解

1.定義消息創建的關聯值 也就是找到方法的標誌

NSString *const GameToIPhoneNotification = @"GameToIPhoneNotification"; GameToIPhoneNotification變量,@"GameToIPhoneNotification"這個值存於通知中心中,信息中心通過這個值來識別變量

1.註冊一個消息中心

NSNotificationCenter *center = [NSNotificationCenter defaultCenter];

[center addObserver:self selector:@selector(onToIphone:) name:GameToIPhoneNotification object:nil];

 

-(void)onToIphone:(NSNotification*)notify :這個方法是接受到GameToIPhoneNotification這個通知所調用的方法

2.調用信息

NSNotificationCenter * center = [NSNotificationCenter defaultCenter];

[center postNotificationName:GameToIPhoneNotification object:nil userInfo:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:SMSRecommendNotification] , @"actcode",nil]];

 

[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithInt:SMSRecommendNotification] 這個是傳遞給-(void)onToIphone:(NSNotification*)notify 的參數。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章