iOS NSNotificationCenter监听移除
来源:互联网 发布:蓄水池算法公式 编辑:程序博客网 时间:2024/06/05 02:42
在UIViewController里面注册通知,页面消失时移除通知。你这边可要注意了,一定要成双成对出现,如果你只在
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(maidanPay:) name:TopUpBlock object:nil];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:TopUpBlock object:nil];
}
viewWillAppear 中 addObserver
没有在viewWillDisappear 中 removeObserver
那么当消息发生的时候,你的方法会被调用多次,这点必须牢记在心。-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(maidanPay:) name:TopUpBlock object:nil];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:TopUpBlock object:nil];
}
0 0
- iOS NSNotificationCenter监听移除
- iOS NSNotificationCenter监听移除
- iOS NSNotificationCenter监听移除
- NSNotificationCenter 移除监听
- iOS 监听 出发 Home键 NSNotificationCenter UIApplicationWillResignActiveNotification
- iOS 监听键盘的高度 - NSNotificationCenter
- 关于NSNotificationCenter的注册和移除
- 移除监听事件
- iOS监听模式系列之NSNotificationCenter的简单使用
- ios NSNotificationCenter
- IOS NSNotificationCenter
- [IOS] NSNotificationCenter
- IOS:NSNotificationCenter
- IOS NSNotificationCenter
- 监听键盘事件NSNotificationCenter
- iOS 控制器POP后dealloc方法不走,通知监听无法移除的问题
- ios移除手势
- iOS 移除CocoaPods
- # 极其重要的线程池 #
- html学习笔记(四)
- Letcode 198 House Robber
- 整理工作中遇到的问题(1)
- Mysql数据库数据类型
- iOS NSNotificationCenter监听移除
- Json序列化中null字段说明
- writeup-JVM EKOPARTY
- 四元数和欧拉角以及方向余弦的区别
- PHP源码分析 - PHP-FPM运行模式详解
- android私有存储目录下的文件如何让其他程序有权限打开
- activiti的taskService.complete方法
- html行间距 行距学习记录
- 获取app信息