NSNotificationCenter 发送 接受处理

来源:互联网 发布:雷云网络不可用 编辑:程序博客网 时间:2024/06/05 21:16
//发送通知 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];    }}

0 0