2012年3月23日 星期五

NSNotification 傳值

準備訊息 NSNotification *notification = [NSNotification notificationWithName:@"UserInfoNotify" object:nil userInfo:[NSDictionary dictionaryWithObjects:userInfoValues forKeys:userInfoKeys]];
發送訊息 [[NSNotificationCenter defaultCenter] postNotification:notification];
註冊觀察者 [[NSNotificationCenter defaultCenter] addObserverForName:@"UserInfoNotify" object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *notification) { NSDictionary *dict = notification.userInfo; }];
移除觀察者 [[NSNotificationCenter defaultCenter] removeObserver:self];
範例下載

沒有留言:

張貼留言