iOS-通知传值
来源:互联网 发布:淘宝手动绞肉机 编辑:程序博客网 时间:2024/04/29 15:50
通知传值要分清楚发送方和接收方
发送方只需要发送通知 而接收方需要3步
1.注册通知
2.写出通知的回调方法
3.移除通知
如果接收通知的一方是用故事版做的 那么注册通知不能写在
viewDidLoad方法里面 而是在在页面将要显示的时候 用
- (instancetype)initWithCoder:(NSCoder *)aDecoder去拦截他的初始化方法 在里面注册通知
像这样
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
self = [superinitWithCoder:aDecoder];
if (self) {
[[NSNotificationCenterdefaultCenter]addObserver:selfselector:@selector(shoudao:)name:@"tongzhi"object:nil];
}
returnself;
}
参数1.通知的名字
参数2.传递的内容
[[NSNotificationCenterdefaultCenter]postNotificationName:@"tongzhi"object:_game];
这样在通知的回调方法里面就可以接收到传递的内容-(void)shoudao:(NSNotification *)info{
NSLog(@"00");
NSLog(@"%@",info);
[self.downLoadArraddObject:info.object];
[self.tableViewreloadData];
}
可以看到info里面就保存了要传递的内容
最后再移除通知
-(void)dealloc{
[[NSNotificationCenterdefaultCenter]removeObserver:self];
}
- iOS通知传值
- iOS通知传值
- IOS 通知传值
- iOS 通知传值
- iOS通知传值
- iOS通知传值
- iOS 通知传值
- iOS通知传值
- iOS通知传值
- iOS-通知传值
- IOS 通知传值
- ios开发-通知传值
- iOS NSNotification 通知传值
- iOS通知如何传值?
- iOS NSNotification 通知传值
- iOS开发 通知传值
- iOS NSNotification 通知传值
- iOS通知传值的使用
- 单相逆变器第三课、系统结构分析梳理
- nyoj10 poj 1088经典滑雪问题
- 夜间模式实现方式
- BCNF范式
- 《数据结构与算法分析java语言描述》学习笔记一
- iOS-通知传值
- 华为路由器域内NAT配置
- AIDL和远程Service调用
- android adb push 与 adb install 差异(两种安装APK的方法)
- Python 通过 BeautifulSoup 将 html 中的表格解析成对象
- 关于批处理命令无法识别Xcopy问题的注意点
- C#控制台基础 判断闰年
- 短信验证下发不成功的原因
- Fragment之11_为什么要使用FragmentActivity, 怎么样使用?