我遇到了如下情况:
Date/Time: 2015-11-23 19:40:34.34 -0600
Launch Time: 2015-11-23 18:49:43.43 -0600
OS Version: iOS 9.1 (13B143)
Report Version: 104
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000c
Triggered by Thread: 7
Thread 7 Crashed:
0 libobjc.A.dylib 0x34fcbac6 objc_msgSend + 6
1 UIFoundation 0x31e7242e +[NSStringDrawingTextStorageSettings threadSpecificStringDrawingTextStorageSettings:] + 62
2 UIFoundation 0x31e675de +[NSString(NSStringDrawing) typesetterBehavior] + 34
3 UIFoundation 0x31e68ae2 __NSStringDrawingEngine + 298
4 UIFoundation 0x31e68908 -[NSString(NSExtendedStringDrawing) drawWithRect:options:attributes:context:] + 144
5 UIKit 0x276aa488 -[UILabel _drawTextInRect:baselineCalculationOnly:] + 4864
6 UIKit 0x2771b40c -[UILabel drawTextInRect:] + 540
7 UIKit 0x2771b1e4 -[UILabel drawRect:] + 88
8 UIKit 0x2771b15e -[UIView(CALayerDelegate) drawLayer:inContext:] + 386
9 QuartzCore 0x26f8b6fc -[CALayer drawInContext:] + 228
10 QuartzCore 0x26f75088 CABackingStoreUpdate_ + 1852
11 QuartzCore 0x270619d0 ___ZN2CA5Layer8display_Ev_block_invoke + 52
12 QuartzCore 0x26f745c8 CA::Layer::display_() + 1168
13 QuartzCore 0x26f588a0 CA::Layer::display_if_needed(CA::Transaction*) + 204
14 QuartzCore 0x26f58560 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
15 QuartzCore 0x26f57a78 CA::Context::commit_transaction(CA::Transaction*) + 368
16 QuartzCore 0x26f5772a CA::Transaction::commit() + 614
17 QuartzCore 0x26f84ed2 CA::Transaction::release_thread(void*) + 310
18 libsystem_pthread.dylib 0x3589e54c _pthread_tsd_cleanup + 508
19 libsystem_pthread.dylib 0x3589e14e _pthread_exit + 86
20 libsystem_pthread.dylib 0x3589db3c _pthread_wqthread + 1044
21 libsystem_pthread.dylib 0x3589d718 start_wqthread + 8
我知道我需要在主线程上执行UIKit代码。但是,我正在努力解决主线程上究竟需要的问题。我是否需要确保在主线程上完成以下声明:
UIView *lineView;
或仅修改如下:
lineView = [[UIView alloc] initWithFrame:CGRectMake(15, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];
我一直在调度代码中包装东西,我仍然遇到同样的崩溃。
感谢。
答案 0 :(得分:1)
您应该运行仅向用户显示内容的UI线程代码。
lineView = [[UIView alloc] initWithFrame:CGRectMake(15, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];
此代码可以在后台线程上运行,但
[superview addSubview: lineView];
应该在主线程上执行。