postNotificationName 訊息傳遞詳解,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 的參數。