iOS消息通知Notification的用法

时间:2019-10-15 20:38:58   收藏:0   阅读:99

1.发送消息

1 NSNotification *notification = [NSNotification notificationWithName:@"selectPosition" object:nil userInfo:@"codeABC" forKey:@"code"];
2 [[NSNotificationCenter defaultCenter]postNotification:notification];

2.接收消息

1 - (void)viewDidLoad {
2     [super viewDidLoad];  
3     [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(selectPosition:) name:@"selectPosition" object:nil];
4 }
5 
6 - (void)selectPosition:(NSNotification *)notification
7 {
8     NSString *code = [notification.userInfo objectForKey:@"code"];
9 }

 

原文:https://www.cnblogs.com/luoluosha/p/11679967.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!