常见的通知

作者: 一蓑丨烟雨 | 来源:发表于2017-05-10 15:17 被阅读4次

一、通知传值:

//发送通知
  NSDictionary *info = @{@"key":@"value"};
  NSNotification *notification = [NSNotification notificationWithName:@"notiName" object:nil userInfo:info];
  [[NSNotificationCenter defaultCenter] postNotification:notification];
    
 //接受通知
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotifi:) name:@"notiName" object:nil];
//得到传递的数据
-(void)receiveNotifi:(NSNotification *)notifi{
    NSDictionary * info = notifi.userInfo;
}

二、通知不传值:

//发送通知
 NSNotification *notification = [NSNotification notificationWithName:@"notiName" object:nil];
 [[NSNotificationCenter defaultCenter] postNotification:notification];
    
  //接受通知
 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveNotifi) name:@"notiName" object:nil];
//收到通知
-(void)receiveNotifi{
    
}

相关文章

网友评论

    本文标题:常见的通知

    本文链接:https://www.haomeiwen.com/subject/epkgtxtx.html