iOS消息通知Notification的用法


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 }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM