通知中心传参

NSDictionary *dict = @{@"color":color, @"userName":@"haha"};
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeBgColor" object:nil userInfo:dict];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeBgColor:) name:@"changeBgColor" object:nil];
- (void)changeBgColor:(NSNotification *)notification{
       NSLog(@"接受到通知,改变背景颜色");
       // 如果是传多个数据,那么需要哪个数据,就对应取出对应的数据即可
       self.view.backgroundColor = notification.userInfo[@"color"];
       UILabel *label = (UILabel *)[self.view viewWithTag:100];
       label.text = notification.userInfo[@"userName"];
}

你可能感兴趣的:(通知中心传参)