iOS 之 通知
步骤一,注册消息:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getUserProfileSuccess:) name:@"Notification_GetUserProfileSuccess" object:nil];
notificationObserver 观察者 : self
notificationSelector 处理消息的方法名: getUserProfileSuccess
notificationName 消息通知的名字: Notification_GetUserProfileSuccess
notificationSender 消息发送者 : 表示接收哪个发送者的通知,如果第四个参数为nil,接收所有发送者的通知
步骤二,发送消息
[[NSNotificationCenter defaultCenter]
postNotificationName:@"Notification_GetUserProfileSuccess"
object:userProfile
userInfo:nil];
步骤三:接收消息
- (void) getUserProfileSuccess: (NSNotification*) aNotification { self.userProfile = [aNotification object]; lblName.text = self.userProfile.Name; }