ios – “只在主线程上运行”异常是模拟器

前端之家收集整理的这篇文章主要介绍了ios – “只在主线程上运行”异常是模拟器前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我得到一个“只运行在主线程”异常深处(或之后)
  1. [self.navigationController pushViewController:controller animated:YES];

事情只发生在模拟器上,而不是在IOS设备中进行调试.
有什么机会我可以解决这个问题吗?

转储:

  1. 2014-03-25 15:18:45.061 Cookila[657:5507] *** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *,UIView<NSTextContainerView> *,NSTextContainer *,NSUInteger)(),/SourceCache/UIFoundation_Sim/UIFoundation-264.8/UIFoundation/TextSystem/NSLayoutManager_Private.m:1510
  2. 2014-03-25 15:18:45.086 Cookila[657:5507] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: 'Only run on the main thread!'
  3. *** First throw call stack:
  4. (
  5. 0 CoreFoundation 0x027251e4 __exceptionPreprocess + 180
  6. 1 libobjc.A.dylib 0x024a48e5 objc_exception_throw + 44
  7. 2 CoreFoundation 0x02725048 +[NSException raise:format:arguments:] + 136
  8. 3 Foundation 0x01f43b20 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 101
  9. 4 UIFoundation 0x0947fe25 -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 419
  10. 5 UIFoundation 0x0947fb0a -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 2083
  11. 6 UIFoundation 0x094b4289 _enableTextViewResizing + 234
  12. 7 UIFoundation 0x094b7e89 -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 688
  13. 8 UIFoundation 0x094b7f0e -[NSLayoutManager processEditingForTextStorage:edited:range:changeInLength:invalidatedRange:] + 82
  14. 9 UIFoundation 0x094e0ab5 -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 153
  15. 10 UIFoundation 0x094e05f0 -[NSTextStorage processEditing] + 462
  16. 11 UIFoundation 0x094e0199 -[NSTextStorage endEditing] + 80
  17. 12 UIFoundation 0x094e0223 -[NSTextStorage coordinateEditing:] + 66
  18. 13 UIKit 0x016618cb -[UITextView setAttributedText:] + 254
  19. 14 UIKit 0x01660c16 -[UITextView initWithCoder:] + 706
  20. 15 UIKit 0x01372d6d UINibDecoderDecodeObjectForValue + 704
  21. 16 UIKit 0x01372f6e UINibDecoderDecodeObjectForValue + 1217
  22. 17 UIKit 0x01372aa1 -[UINibDecoder decodeObjectForKey:] + 114
  23. 18 UIKit 0x00faafa4 -[UIView initWithCoder:] + 842
  24. 19 UIKit 0x01372d6d UINibDecoderDecodeObjectForValue + 704
  25. 20 UIKit 0x01372f6e UINibDecoderDecodeObjectForValue + 1217
  26. 21 UIKit 0x01372aa1 -[UINibDecoder decodeObjectForKey:] + 114
  27. 22 UIKit 0x00faafa4 -[UIView initWithCoder:] + 842
  28. 23 UIKit 0x00fcdff1 -[UIScrollView initWithCoder:] + 58
  29. 24 UIKit 0x01372d6d UINibDecoderDecodeObjectForValue + 704
  30. 25 UIKit 0x01372aa1 -[UINibDecoder decodeObjectForKey:] + 114
  31. 26 UIKit 0x0120d7a7 -[UIRuntimeConnection initWithCoder:] + 191
  32. 27 UIKit 0x01372d6d UINibDecoderDecodeObjectForValue + 704
  33. 28 UIKit 0x01372f6e UINibDecoderDecodeObjectForValue + 1217
  34. 29 UIKit 0x01372aa1 -[UINibDecoder decodeObjectForKey:] + 114
  35. 30 UIKit 0x0120cc21 -[UINib instantiateWithOwner:options:] + 1117
  36. 31 UIKit 0x010756f5 -[UIViewController _loadViewFromNibNamed:bundle:] + 280
  37. 32 UIKit 0x01075e9d -[UIViewController loadView] + 302
  38. 33 UIKit 0x010760d3 -[UIViewController loadViewIfrequired] + 78
  39. 34 UIKit 0x010765d9 -[UIViewController view] + 35
  40. 35 UIKit 0x01090942 -[UINavigationController _startCustomTransition:] + 778
  41. 36 UIKit 0x0109d8f7 -[UINavigationController _startDeferredTransitionIfNeeded:] + 688
  42. 37 UIKit 0x0109e4e9 -[UINavigationController __viewWillLayoutSubviews] + 57
  43. 38 UIKit 0x011df0d1 -[UILayoutContainerView layoutSubviews] + 213
  44. 39 UIKit 0x00fc6964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
  45. 40 libobjc.A.dylib 0x024b682b -[NSObject performSelector:withObject:] + 70
  46. 41 QuartzCore 0x00e2e45a -[CALayer layoutSublayers] + 148
  47. 42 QuartzCore 0x00e22244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
  48. 43 QuartzCore 0x00e220b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
  49. 44 QuartzCore 0x00d887fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
  50. 45 QuartzCore 0x00d89b85 _ZN2CA11Transaction6commitEv + 393
  51. 46 QuartzCore 0x00d89dd6 _ZN2CA11Transaction14release_threadEPv + 226
  52. 47 libsystem_pthread.dylib 0x031f581c _pthread_tsd_cleanup + 93
  53. 48 libsystem_pthread.dylib 0x031f227e _pthread_exit + 108
  54. 49 libsystem_pthread.dylib 0x031f21e8 pthread_exit + 33
  55. 50 Foundation 0x01ef1dd2 __NSFinalizeThreadData + 0
  56. 51 Foundation 0x01eee97e __NSThread__main__ + 1299
  57. 52 libsystem_pthread.dylib 0x031f15fb _pthread_body + 144
  58. 53 libsystem_pthread.dylib 0x031f1485 _pthread_struct_init + 0
  59. 54 libsystem_pthread.dylib 0x031f6cf2 thread_start + 34
  60. )
  61. libc++abi.dylib: terminating with uncaught exception of type NSException

解决方法

请从主线程做你的UI回调.你不能从后台线程更新您的UI.

使用Grand Central Dispatch进行UI更新:

  1. dispatch_async(dispatch_get_main_queue(),^{
  2. /* Your UI code */
  3. });

猜你在找的iOS相关文章