iOS报错terminate_handler unexpectedly threw an exception
2017-07-13 10:54
369 查看
今天遇到了一个非常奇葩的坑,但是我又不得不承认这也算是一个bug。 由于感觉这可能是万分之一的踩坑概率,所以我想把这个记录下来, 万一有和我一样莫名其妙被坑的人呢,嘿嘿......
早上有公司小姑娘找我说这个页面闪退,打不开。我默默拿出自己的手机试了一下,简直是完美无bug,并没有她说的闪退。我设想了各种可能,也许是她的账号数据的问题,或者她手机内存不足吧之类的。结果用我的手机登录了她的账号之后,并没有闪退,这就排除了账号问题。于是我用她的手机断点调试了一下,报错terminate_handler unexpectedly threw an exception,而且就崩溃在了下面这段代码块。于是我把这个代码注释了之后她的手机终于不闪退了。这个时候真相浮出了水面,这个姑娘手机的语言设置的是德语!!!(摊手)德国回来的妹子就是洋气。。。。。。于是我长了见识,德语中的小数点是逗号,类似100,00这种写法。所以为了迎合小姑娘用德语的心愿,我不得不加了一下判断。
下面介绍一下具体实现的方法。
+ (NSMutableAttributedString *)setAmountStringRoundNumberColor:(UIColor *)roundColor font:(UIFont *)roundFont DecimalNumberColor:(UIColor *)decimalColor font:(UIFont *)decimalFont TotalString:(NSString *)totalString { NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:totalString]; // 整数部分 NSRange range; if([totalString rangeOfString:@"."].location !=NSNotFound)//_roaldSearchText { range = [totalString rangeOfString:@"."]; } else { range = [totalString rangeOfString:@","]; } NSString *rangeString = [totalString substringToIndex:range.location + 1]; NSRange roundRange = [totalString rangeOfString:rangeString options:NSBackwardsSearch]; [attributedStr addAttribute:NSForegroundColorAttributeName value:roundColor range:roundRange]; [attributedStr addAttribute:NSFontAttributeName value:roundFont range:roundRange]; // 小数部分 NSString *leftString = [totalString substringFromIndex:range.location + 1]; rangeString = [totalString substringWithRange:NSMakeRange(range.location + 1, leftString.length - 1)]; NSRange decimalRange = [totalString rangeOfString:rangeString options:NSBackwardsSearch]; [attributedStr addAttribute:NSForegroundColorAttributeName value:decimalColor range:decimalRange]; [attributedStr addAttribute:NSFontAttributeName value:decimalFont range:decimalRange]; return attributedStr; }
相关文章推荐
- iOS libc++abi.dylib: terminate_handler unexpectedly threw an exception
- 【iOS】libc++abi.dylib: terminate_handler unexpectedly threw an exception
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- terminate_handler unexpectedly threw an exception
- NSScanner: nil string argument libc++abi.dylib: terminate_handler unexpectedly threw an exception问题
- libc++abi.dylib: terminate_handler unexpectedly threw an exception//NSScanner: nil string argument
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- UIActionSheet :libc++abi.dylib: terminate_handler unexpectedly threw an exception
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- 解决libc++abi.dylib: terminate_handler unexpectedly threw an exception(1)
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- libc++abi.dylib: terminate_handler unexpectedly threw an exception 报错
- libc++abi.dylib: terminate_handler unexpectedly threw an exception错误小结
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- 解决报错libc++abi.dylib: terminate_handler unexpectedly threw an exception
- libc abi.dylib: terminate_handler unexpectedly threw an exception
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- 对于libc++abi.dylib: terminate_handler unexpectedly threw an exception 异常处理如何调试错误
- libc++abi.dylib: terminate_handler unexpectedly threw an exception
- 关于 libc++abi.dylib: terminate_handler unexpectedly threw an exception