通知中心

来源:互联网 发布:mac 照片如何全屏 编辑:程序博客网 时间:2024/04/27 14:08
1、不带参数(1)先发送通知  —— 要传值的页面 (也可以是xib里的传到ViewCtl)//无参数的通知中心[[NSNotificationCenter defaultCenter] postNotificationName:@"post" object:nil];(2)监听通知 —— 要相应的页面//监听通知[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(note) name:@"post" object:nil];(3)监听后执行的方法 —— 要相应的页面//监听通知- ( void ) note  {  ……  }2、带参数(1)先发送通知  —— 要传值的页面 //带参数的通知中心                        将传递的数据作为对象传递[[NSNotificationCenter defaultCenter] postNotificationName:@"postwoods" object:@(number)];(2)监听通知 —— 要相应的页面//带参数的通知监听[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(note:) name:@"postwoods" object:nil];(3)监听后执行的方法 —— 要相应的页面//带参数的通知事件实现- (void)note:(NSNotification *)note{      NSNumber *number = note.object;       新建原数据的类型,赋值传递来的数据}
0 0