iOS使用NSNotificationCenter通知崩溃
来源:互联网 发布:大数据解决方案的公司 编辑:程序博客网 时间:2024/06/08 09:57
至于NSNotificationCenter通知的使用,博主在这里不多讲,百度会出来一大堆,但是今天博主在使用通知时,出现一个问题,就是在iPhone6+以上机子使用时都没问题,但是在5S上使用直接crash了,博主先使用5S模拟器发现没问题,就差看了一下同事5S机子系统,发现是iOS8.2系统,打了一下全剧断点,断在通知处,且是主线程crash
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeState) name:@"changeState" object:nil];
[[NSNotificationCenter defaultCenter] postNotificationName:@"changeState" object:nil];=因此博主怀疑是之前不细心使用通知没有移除掉,因此增加了一个dealloc方法调用移除通知方法,因为博主在这ViewController中只使用了一个通知,就没有针对通知名去移除
- (void)dealloc{ [super dealloc]; [[NSNotificationCenter defaultCenter] removeObserver:self];}因为在iOS8.0中,通知没有移除,就会被调用,而此时他虽然被销毁了没有被置为nil,当调用了一个被销毁的对象时自然就会发生crash,因此为了代码严谨性,使用通知时必须针对通知名去进行销毁。
阅读全文
1 0
- iOS使用NSNotificationCenter通知崩溃
- iOS通知NSNotificationCenter的使用
- ios NSNotificationCenter通知的使用
- 快速使用 NSNotificationCenter iOS通知
- IOS中通知中心(NSNotificationCenter)的使用
- IOS中通知中心(NSNotificationCenter)的使用
- iOS--通知的使用(NSNotificationCenter )
- iOS中通知的使用NSNotificationCenter
- iOS之NSNotificationCenter通知中心使用事项
- iOS 通知中心(NSNotificationCenter)的使用
- iOS开发之NSNotificationCenter(通知)使用介绍
- iOS 键盘通知(NSNotificationCenter)正确使用
- iOS中通知的使用NSNotificationCenter
- iOS开发:NSNotificationCenter,通知中心的使用
- IOS 之 通知NSNotificationCenter
- IOS NSNotificationCenter 通知中心
- IOS NSNotificationCenter 通知中心
- iOS通知中心(NSNotificationCenter)
- <? extends Fruit>与<? super Apple>的理解
- JAVA配置环境变量
- Ubuntu 下 Thunderbird 和 exchange 配置
- 2017初二上期中考试总结
- 构建深度学习环境(基于Pycharm/Python/Tensorflow/Linuxx系统/VMware的开发平台构建)
- iOS使用NSNotificationCenter通知崩溃
- 解决 Tomcat 端口被占用(Tomcat port is occupied)
- jieba结巴分词--关键词抽取
- easyUI
- AndroidStudio使用之——两种方式添加类注释模板
- centos7安装卸载软件
- 匀速运动(js)
- 解密Hibernate @GenericGenerator注解中的strategy属性
- Spring基础---自动装配的方式