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