iOS NSNotificationCenter监听移除
来源:互联网 发布:linux 进入vim命令 编辑:程序博客网 时间:2024/06/06 04:04
在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
- 主要介绍了有关矩阵、向量求导以及链式求导
- Android studio 9图制作
- 闭包与block-捕获变量差异
- 星火计划ROS机器人Spark
- 11-S3C2440驱动学习(五)嵌入式linux-网络设备驱动(二)移植DM9000C网卡驱动程序
- iOS NSNotificationCenter监听移除
- [Leetcode] 162. Find Peak Element 解题报告
- 矩形嵌套 DAG
- JDBC、JDBCTemplate、MyBatis、Hiberante 比较与分析
- HttpClient使用示例
- 设计模式学习总结之工厂模式
- OpenSL ES 进行音频解码播放
- plsql方式导入带有外键约束的表
- Android 开发:由模块化到组件化(一)