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; 新建原数据的类型,赋值传递来的数据
}
通知中心
最新推荐文章于 2024-03-03 23:38:12 发布