美文网首页
ObjC:通知--多发送,一接收

ObjC:通知--多发送,一接收

作者: 叶舞清风 | 来源:发表于2019-05-28 18:10 被阅读0次
    // 接收方
    - (void)viewDidLoad {
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        self.dataArray = [NSMutableArray arrayWithObjects:@"原始数据01",@"原始数据02", nil];
        [self.view addSubview:self.testTableview];
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noti:) name:@"noti" object:nil];
    }
    -(void)noti:(NSNotification *)noti
    {
        NSDictionary *dic = [noti userInfo];
        NSArray * title = dic[@"title"];
        if ([dic[@"typeID"] integerValue] == 1) {
            self.dataArray = [NSMutableArray arrayWithArray:title];
        }
        if ([dic[@"typeID"] integerValue] == 2) {
            self.dataArray = [NSMutableArray arrayWithArray:title];
        }
        if ([dic[@"typeID"] integerValue] == 3) {
            self.dataArray = [NSMutableArray arrayWithArray:title];
        }
        //刷新表格
        [self.testTableview reloadData];
    }
    
    
    // 发送方1
    - (void)addNotifiAction{
        NSArray *dataArray = @[@"OneView123",@"OneView345",@"OneView678"];
        NSDictionary *dic = @{@"title":dataArray,@"typeID":@(1)};
        [[NSNotificationCenter defaultCenter] postNotificationName:@"noti" object:nil userInfo:dic];
    }
    
    // 发送方2
    - (void)addNotifiAction{
        NSArray *dataArray = @[@"TwoView12",@"TwoView34",@"TwoView56",@"TwoView78"];
        NSDictionary *dic = @{@"title":dataArray,@"typeID":@(2)};
        [[NSNotificationCenter defaultCenter] postNotificationName:@"noti" object:nil userInfo:dic];
    }
    
    // 发送方3
    - (void)addNotifiAction{
        NSArray *dataArray = @[@"ThreeView1",@"ThreeView2",@"ThreeView3",@"ThreeView4",@"ThreeView5"];
        NSDictionary *dic = @{@"title":dataArray,@"typeID":@(3)};
        [[NSNotificationCenter defaultCenter] postNotificationName:@"noti" object:nil userInfo:dic];
    }
    

    相关文章

      网友评论

          本文标题:ObjC:通知--多发送,一接收

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