//发送通知
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
//第二个参数是我们要传得值 ,这个参数必须是对象
NSNotification *not = [NSNotification notificationWithName:@"3" object:[NSString stringWithFormat:@"%d",num]];
[center postNotification:not];
//接收消息
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
[center addObserver:self selector:@selector(secondDoWithNOtification:) name:@"3" object:nil];
//发送的有参数 实现的功能也要有参数 而且是NSNotification类型的参数
-(void)secondDoWithNOtification:(NSNotification*)notice
{
//把收到的通知参数转为字符串
NSString *object = [notice object];
NSLog(@"%@",object);
if ([object intValue] == 0) {
UIButton *btn = (UIButton*)[self.view viewWithTag:1000];
[btn removeFromSuperview];
}else{
UIButton *btn = (UIButton*)[self.view viewWithTag:1001];
[btn removeFromSuperview];
}
}
NSNotificationCenter 发送 接受处理
最新推荐文章于 2022-11-20 19:08:53 发布