ios - iOS 中的奇怪崩溃

标签 ios objective-c crash nsrangeexception

crittercism 报告了一组崩溃。

我从未复制过它,但在 1 周内有大约 50 次来自不同的用户。

21
XXApp 0x0000000100129fb0 -[NSString(XXFormat) attributedStringFromHTMLByFont:] (NSString+XXFormat.m:15) 崩溃了。

以下是NSString+XXFormat.m中第15行的代码:

NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithData:[self dataUsingEncoding:NSUTF8StringEncoding]
                                                                                options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType,
                                                                                          NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)}
                                                                     documentAttributes:nil error:nil];

名称:NSRangeException

原因:*** -[__NSArrayM objectAtIndex:]: 索引 3 超出范围 [0 .. 2]

堆栈:

0   
CoreFoundation 0x0000000183a0c2d8 __exceptionPreprocess + 128
1   
libobjc.A.dylib 0x00000001952380e4 objc_exception_throw + 56
2   
CoreFoundation 0x00000001838ef85c -[__NSArrayM objectAtIndex:] + 260
3   
UIKit 0x0000000188575a94 -[UITableView cellForRowAtIndexPath:] + 212
4   
UIKit 0x000000018873fa00 -[UITableViewWrapperView gestureRecognizerShouldBegin:] + 284
5   
UIKit 0x00000001885e2c34 -[UIGestureRecognizer _shouldBegin] + 1072
6   
UIKit 0x000000018847b340 -[UIGestureRecognizer setState:] + 428
7   
UIKit 0x00000001885f4fdc -[UIScrollViewPanGestureRecognizer touchesMoved:withEvent:] + 100
8   
UIKit 0x000000018847a6d8 -[UIWindow _sendGesturesForEvent:] + 592
9   
UIKit 0x0000000188479f50 -[UIWindow sendEvent:] + 656
10  
UIKit 0x000000018844d18c -[UIApplication sendEvent:] + 260
11  
UIKit 0x00000001886ee324 _UIApplicationHandleEventFromQueueEvent + 15420
12  
UIKit 0x000000018844b6a0 _UIApplicationHandleEventQueue + 1712
13  
CoreFoundation 0x00000001839c4240 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 20
14  
CoreFoundation 0x00000001839c359c __CFRunLoopDoSources0 + 444
15  
CoreFoundation 0x00000001839c1594 __CFRunLoopRun + 708
16  
CoreFoundation 0x00000001838ed2d4 CFRunLoopRunSpecific + 392
17  
UIFoundation 0x0000000191850c10 -[NSHTMLReader _loadUsingWebKit] + 1984
18  
UIFoundation 0x0000000191851fd0 -[NSHTMLReader attributedString] + 28
19  
UIFoundation 0x00000001917ef23c _NSReadAttributedStringFromURLOrData + 5800
20  
UIFoundation 0x00000001917edad8 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 144

21  
XXApp 0x0000000100129fb0 -[NSString(XXFormat) attributedStringFromHTMLByFont:] (NSString+XXFormat.m:15)

22  
XXApp 0x0000000100112f64 -[XXNews(Peer) attributedContent] (XXNews+Peer.m:56)
23  
XXApp 0x00000001000fc854 -[XXWidgetNewsCell setWidget:] (XXWidgetNewsCell.m:53)
24  
XXApp 0x0000000100116ba4 -[XXTimeLineTableViewController tableView:cellForRowAtIndexPath:] (XXTimeLineTableViewController.m:231)
25  
UIKit 0x000000018874da68 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 540
26  
UIKit 0x0000000188741890 -[UITableView _updateVisibleCellsNow:isRecursive:] + 2360
27  
UIKit 0x000000018852d268 -[UITableView layoutSubviews] + 168
28  
UIKit 0x0000000188449760 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 576
29  
QuartzCore 0x0000000187d91e1c -[CALayer layoutSublayers] + 148
30  
QuartzCore 0x0000000187d8c884 CA::Layer::layout_if_needed() + 316
31  
QuartzCore 0x0000000187d8c728 CA::Layer::layout_and_display_if_needed() + 28
32  
QuartzCore 0x0000000187d8bebc CA::Context::commit_transaction() + 272
33  
QuartzCore 0x0000000187d8bc3c CA::Transaction::commit() + 524
34  
QuartzCore 0x0000000187d85364 CA::Transaction::observer_callback() + 76
35  
CoreFoundation 0x00000001839c42a4 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 28
36  
CoreFoundation 0x00000001839c1230 __CFRunLoopDoObservers + 356
37  
CoreFoundation 0x00000001839c1610 __CFRunLoopRun + 832
38  
CoreFoundation 0x00000001838ed2d4 CFRunLoopRunSpecific + 392
39  
GraphicsServices 0x000000018d1036fc GSEventRunModal + 164
40  
UIKit 0x00000001884b2fac UIApplicationMain + 1484
41  
XXApp 0x0000000100101280 main (main.m:14)
42  
libdyld.dylib 0x00000001958b6a08 start + 0

最佳答案

导致问题的不是您在此处共享的代码段,而是您试图访问数组中不存在的元素:

Name: NSRangeException

Reason: *** -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]

数组有边界 [0 .. 2] 并且您尝试访问不存在元素的索引 3

确保在您的方法 cellForRowAtIndexPath 中您没有绕过 NSArray 的索引

关于ios - iOS 中的奇怪崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31451119/

相关文章:

ios - "Unknown type name"使用 YACC 和 xcode

android - 如果 google play 上的应用程序进行逆向工程,崩溃是否会出现在我的应用程序在 google play 控制台上的崩溃中?

ios - 在 Launchpad (Mac) 或 iPhone 的主菜单中滑动页面

ios - 如果对象是观察者并在通知中心注册,如何调用 dealloc 方法?

ios - 如何删除导航栏底部颜色 iOS 7

iOS:CCCrypt() kCCOptionECBMode 和 kCCModeCBC 哪个更安全

ios - Flutter IOS 使用连接或 wifi 插件读取 wifi 名称

ios - 将 customTableCell 中的 View 设置为在 beginUpdate 和 endUpdate 后可见

ios - 锁定屏幕或进入后台时 OpenGL ES 应用程序崩溃

ios - 在 for 循环中添加字符串会导致 ios 设备崩溃