利用系统NSNotification通知来实现页面之间的传值
方法如下:
在A页面ViewDidLoad中注册一个通知
- //注册通知, 进行传值 name:@"RELOADVOEWNOTIFICATION"这个就是其唯一标示符.系统是用来做鉴别其惟一性,就是设备标示符一样
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadView:) name:@"RELOADVOEWNOTIFICATION" object:nil];
- //发送通知 array是携带的数组
- [[NSNotificationCenter defaultCenter] postNotificationName:@"RELOADVOEWNOTIFICATION" object:array];
- - (void)reloadView: (NSNotification *)sender
- {
- //这里Sender有一个属性就是object,这个就是所传过来的值.本文中为array这个数组.
- NSMutableArray *array = sender.object;
- NSLog(@"array:%@", array);
- }
这里要注意的是要保证注册和发送的Name是一样的.这样A页面中所注册的消息才可以接收到.