1. 程式人生 > >通知傳值 ( 多傳送 , 1接收)

通知傳值 ( 多傳送 , 1接收)

三個通知方: 第一個

NSDictionary *dic = @{@"title":TextField.text,@"typeID":@(1)};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"noti" object:nil userInfo:dic];

第二個

NSDictionary *dic = @{@"title":textArr[indexPath.row],@"typeID":@(2)};
      [[NSNotificationCenter defaultCenter] postNotificationName:@"noti" object:nil userInfo:dic];

第三個

NSDictionary *dic = @{@"title":TextField.text,@"typeID":@(3)};
    [[NSNotificationCenter defaultCenter] postNotificationName:@"noti" object:nil userInfo:dic];

接收方

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(noti:) name:@"noti" object:nil];


-(void)noti:(NSNotification *)noti {
    NSDictionary *dic = [noti userInfo];
    NSString * title = dic[@"title"];
    if ([dic[@"typeID"] integerValue]==1) {
        //Name
        _nichengString = title;
    }
    if ([dic[@"typeID"] integerValue]==2) {
        //GongSi
        _gongsiString2 = title;
    }
    if ([dic[@"typeID"] integerValue]==3) {
        //nicheng
        _xingmingString = title;
    }
    //重新整理表格
     [_tbv reloadData];
}