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;

}

 

posted on 2015-12-20 15:52  大木哥  阅读(159)  评论(0编辑  收藏  举报

导航