【发布时间】:2014-05-01 02:50:10
【问题描述】:
即使 iOS 文档说:
可以访问NLayoutManager、NSTextStorage和NSTextContainer 只要应用程序保证从单个子线程访问 线程。
我偶尔会遇到这个异常:
由于未捕获的异常而终止应用程序 'NSInternalInconsistencyException',原因:'只在主服务器上运行 线程!'
这是回溯:
Exception Type: SIGABRT
Exception Codes: #0 at 0x197bca58c
Crashed Thread: 7
Application Specific Information:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
Last Exception Backtrace:
0 CoreFoundation 0x000000018afd2f50 __exceptionPreprocess + 132
1 libobjc.A.dylib 0x00000001974dc1fc objc_exception_throw + 56
2 CoreFoundation 0x000000018afd2e10 +[NSException raise:format:arguments:] + 112
3 Foundation 0x000000018bb0ae20 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 84
4 UIFoundation 0x00000001940f0654 -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 412
5 UIFoundation 0x00000001940f0318 -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 1748
6 UIFoundation 0x000000019411ec2c _enableTextViewResizing + 236
7 UIFoundation 0x0000000194123e18 -[NSLayoutManager textContainerForGlyphAtIndex:effectiveRange:] + 484
8 UIFoundation 0x0000000194125c60 -[NSLayoutManager glyphRangeForTextContainer:] + 352
需要注意的一点是我的NLayoutManager 附加到UITextView。您可以将其视为普通的UITextView,用于在后台线程中进行文本布局。
那么这是否意味着与文档所说的相矛盾,如果NLayoutManager 附加到UITextView,则它不能安全地用于单个后台线程?
【问题讨论】:
-
您找到解决方案了吗?我现在遇到了同样的问题。我想在后台使用一个单元格来重新计算大小。
标签: ios textkit nslayoutmanager