综合出现NSScanner: nil string argument libc++abi.dylib: terminat错误的解决方案
在开发中出现了这个错误,断点查找很久,没找到问题所在的代码,google下,发现了下面这几点会产生这个错误:
- 首先,顾名思义,错误原因是我们在调用某个方法的时候,传入了一个空字符串(注意区别于字符串内容为空)作为方法参数。
- 对某一个空数组使用objectAtIndex方法。不会报数组越界的错,而是NSScanner: nil string argument。
经过检查,我代码中如果字符串赋值,我一般都对nil做了一定处理,用@""代替,也未有数组越界,但是还是报这样的错误。
现在的信息点是libc++abi.dylib,这个库到底是做什么的?从后缀看,是一个动态库,那么会不会是因为发生了一些动态错误?而按经验来看,一般的动态错误基本是因为动态类型错误引起,在object-c语言中,会发生动态类型错误的可能基本存在于不可变类型与可变类型之间的转换,那么我们的查错范围将优先限制在不可变类型与可变类型转换上,是否我们对一个不可变类型进行了修改操作?当然,编译器没有那么傻,如果直接对一个不可变类型进行修改操作,是会直接报错的,那么就剩下另一种可能,程序将一个不可变类型赋值给可变类型,然后对可变类型进行了修改操作,这样可以通过静态检查,但是动态运行的时候,就会发生类型错误。基于以上分析,我们可以跟踪断点,会发现程序在对mutable对象进行add、set等操作时挂掉,而这个对象实际上赋值的是一个不可变对象。常见的情况是把一个NSArray对象赋值给一个NSMutableArray对象,然后进行了delete、add等修改操作,或者把一个NSDictionary对象赋值给一个NSMutableDictionary对象,然后进行了set等操作。
这是从http://www.itnose.net/detail/6196671.html里面得来的方案,经过排查,代码表面上也未有这样的错误。
然后找到最后崩溃处的断点代码如下:
NSDictionary *orderDict = [notification userInfo];
self.selectedOrderDict = orderDict;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:@[indexPath], nil] withRowAnimation:UITableViewRowAnimationNone];
灵机一动,其实是实在不知道怎么改了,于是改成了下面的代码,然后编译,运行,既然可以了。。。。。。
NSDictionary *orderDict = [notification userInfo];
self.selectedOrderDict = orderDict;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
NSMutableArray *tmpArray = [NSMutableArray array];
[tmpArray addObject:indexPath];
[self.tableView reloadRowsAtIndexPaths:tmpArray withRowAnimation:UITableViewRowAnimationNone];
不解,既然这样就可以了,可是从代码层次、逻辑层次来说,这两种写法应该是一样的,难道是这个借口需要的是可变的数组?于是打开里面的接口,发现是这样的:
- (void)reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation NS_AVAILABLE_IOS(3_0);
当时我的心情是崩溃的,尼玛,那啥意思,于是有了下面的测试:
NSDictionary *orderDict = [notification userInfo];
self.selectedOrderDict = orderDict;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
// NSMutableArray *tmpArray = [NSMutableArray array];
// [tmpArray addObject:indexPath];
// [self.tableView reloadRowsAtIndexPaths:tmpArray withRowAnimation:UITableViewRowAnimationNone];
NSArray *tmpArray = @[indexPath];
[self.tableView reloadRowsAtIndexPaths:tmpArray withRowAnimation:UITableViewRowAnimationNone];
这样也是不崩溃的......
好吧,到这,还是没发现错误原因,然后回去仔细看看面前的代码,发现
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:self.selectedRow inSection:0];
[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:@[indexPath], nil] withRowAnimation:UITableViewRowAnimationNone];
indexPath本身就是个对象了,而我还用NSValues包装它,放进去,肯定不能解析而崩溃啊......
综合出现NSScanner: nil string argument libc++abi.dylib: terminat错误的解决方案的更多相关文章
- oc for in 的时候nsscanner: nil string argument
今天偶然发现,oc for in 动态的给一数组加东西,然后嵌套for in 会报nsscanner: nil string argument. 换成for循环就好了,暂时还没找到原因
- 新浪微博分享出现libc++abi.dylib: terminating with uncaught exception of type NSException微博微信SDK运行编译报错
SDK出现libc++abi.dylib: terminating with uncaught exception of type NSException 的问题: 解决方法 结合 # 监测bug( ...
- iOS - libc++abi.dylib: terminate_handler unexpectedly threw an exception
代码出现crash,报错:libc++abi.dylib: terminate_handler unexpectedly threw an exception 当我们很明确是某一块代码执行导致了错误, ...
- 如何调试libc++abi.dylib handler threw exception错误
From:http://blog.csdn.net/naruto_ku/article/details/8779203 在进行iOS开发时,偶尔会碰到libc++abi.dylib handler t ...
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
说法一: 我们在运行xcode工程时,有时候会遇到”libc++abi.dylib: terminate_handler unexpectedly threw an exception”错误,app莫 ...
- libc++abi.dylib handler threw exception
在iOS开发时,有时候遇到libc++abi.dylib handler threw exception这样的异常, 虽然在断点出加上了All Exceptions,也断到相应的代码了,但是没打印对 ...
- mac python3 conda pytorch出错:libc++abi.dylib: terminating with uncaught exception of type NSException
mac 10.14/ conda/python 3.7环境下运行神经网络例子出现错误: -- :::] -[NSApplication _setup:]: unrecognized selector ...
- IOS Exception 1(libc++abi.dylib: terminating with uncaught exception of type NSException)
2014-08-05 22:18:46.455 SwiftUI[1329:40871] -[_TtC7SwiftUI14MViewControler clickMe]: unrecognized se ...
- libc++abi.dylib`__cxa_throw: 使用[AVAudioPlayer play]会产生__cxa_throw异常
libc++abi.dylib`__cxa_throw: 使用[AVAudioPlayer play]会产生__cxa_throw异常 开发中遇到一个奇怪的异常.我调用AVAudioPlayer pl ...
随机推荐
- oracle下导出某用户所有表的方法
oracle下导出某用户所有表的方法 scott/tiger是用户名和密码,handson是导出的实例名 按用户方式导出数据(owner当中写的是用户名) exp scott/tiger@handso ...
- 【js】在js中加HTML注释标签的原因?
<script type="text/JavaScript"> <!-- js代码 //--> //就是这句,为什么还要在-->前加上js注释 < ...
- Android Framework中的线程Thread及它的threadLoop方法
当初跟踪Camera的代码中的时候一直追到了HAL层,而在Framework中的代码看见了许很多多的Thread.它们普遍的特点就是有一个threadLoop方法.依照字面的意思应该是这个线程能够循环 ...
- Java 8 – TemporalAdjusters examples
1. TemporalAdjusters Example to move a date to firstDayOfMonth, firstDayOfNextMonth, next Monday and ...
- JavaScript 循环:如何处理 async/await
如何串行或者并行运行异步循环? 在使用循环处理异步的魔法之前,我们先来看下我们是怎么处理同步循环的. 同步循环 很久以前我写的循环是这样的: for (var i = 0; i < array. ...
- 怎么在eclipse中安装svn插件
Subclipse Subclipse is an Eclipse Team Provider plug-in providing support for Subversion within th ...
- sysbench压力测试工具安装和参数介绍
一.sysbench压力测试工具简介: sysbench是一个开源的.模块化的.跨平台的多线程性能测试工具,可以用来进行CPU.内存.磁盘I/O.线程.数据库的性能测试.目前支持的数据库有MySQL. ...
- [LintCode] N-Queens
N-Queens The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no tw ...
- Android开源之BaseRecyclerViewAdapterHelper(持续更新!)
官方地址:http://www.recyclerview.org/ 文档 v1.9.8 English 中文 v2.0.0 English 中文 Extension library PinnedSec ...
- jquery 取子节点及当前节点属性值
分享下jquery取子节点及当前节点属性值的方法. <li class="menulink"><a href="#" rel="ex ...