常见的通知
2017-05-10 本文已影响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{
}