NSNotificationCenter通知传参数

来源:互联网 发布:免费聊天相亲软件 编辑:程序博客网 时间:2024/04/29 13:26

 //发送通知   (_seletedModel表示要传递的对象参数)

        [[NSNotificationCenterdefaultCenter]postNotificationName:@"categoryDidChanged"object:niluserInfo:@{@"categoryModel":_seletedModel}];




//添加观察者

    [[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(categoryChange:)name:@"categoryDidChanged"object:nil];

//CategoriyModel为自定义的模型

- (void)categoryChange:(NSNotification*)noti{

    CategoriyModel *md = (CategoriyModel*)noti.userInfo[@"categoryModel"];

    NSLog(@"%@",md.name);

}



0 0
原创粉丝点击