iOS訊息NSNotificationCenter通知傳值到不同介面

2020-08-08 13:13:28

首先,先註冊一個訊息通知:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSDictionary *jsonDict = [_temp objectAtIndex:indexPath.row];
   [[NSNotificationCenter defaultCenter]postNotificationName:@"zixun" object:nil userInfo:@{@"cellKey":jsonDict[@"title"]}];
    [WTSDK Ins].giftStr = jsonDict[@"title"];
    NSLog(@"%@列印的pppppp=====",[WTSDK Ins].giftStr);
    [self cellEvent];
}

然後,另一個介面接收傳來的通知:

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

實現方法:

- (void)editBtn:(NSNotification *)sender{
 self.content_Value = sender.userInfo[@"cellKey"];
 NSLog(@"%@self.content_Value==",self.content_Value);
}

這樣子就可以了