【问题标题】:Random crash on setting UITabBarButton label attributed text (Tab Title)设置 UITabBarButton 标签属性文本(标签标题)时随机崩溃
【发布时间】:2014-02-28 02:02:25
【问题描述】:

我无法重现此崩溃,但在生产版本中多次收到此类崩溃。在我的应用程序中,标签栏仅从情节提要加载,并且始终隐藏标签栏。

它的主要原因是内存不足吗?任何猜测,如何解决或重现此类问题

Hardware Model:      iPad2,4
OS Version:      iPhone OS 7.0.4 (11B554a)
Report Version:  104

Exception Type:  SIGABRT
Exception Codes: #0 at 0x393f71fc
Crashed Thread:  0

Application Specific Information:
*** Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray replaceObjectsInRange:withObject:length:: Out of bounds'

Last Exception Backtrace:
0   CoreFoundation                      0x2e766f4b __exceptionPreprocess + 131
1   libobjc.A.dylib                     0x38e386af objc_exception_throw + 38
2   CoreFoundation                      0x2e766e8d +[NSException raise:format:] + 104
3   Foundation                          0x2f089aff -[NSMutableRLEArray replaceObjectsInRange:withObject:length:] + 122
4   Foundation                          0x2f088efb -[NSConcreteMutableAttributedString initWithString:attributes:] + 310
5   UIKit                               0x30ee8ed7 -[NSAttributedString(UILabelAdditions) _ui_synthesizeAttributedSubstringFromRange:usingDefaultAttributes:] + 86
6   UIKit                               0x30ee8c9f -[UILabel _synthesizedAttributedText] + 1010
7   UIKit                               0x30ee8307 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 222
8   UIKit                               0x30ee8213 -[UILabel textRectForBounds:limitedToNumberOfLines:] + 54
9   UIKit                               0x30ee80fb -[UILabel _intrinsicSizeWithinSize:] + 162
10  UIKit                               0x30ee8049 -[UILabel sizeThatFits:] + 32
11  UIKit                               0x30ee7f37 -[UIView(Geometry) sizeToFit] + 126
12  UIKit                               0x31002be1 -[UITabBarButton initWithImage:selectedImage:label:withInsets:] + 388
13  UIKit                               0x31001a1f -[UITabBarItem(Static) _createViewForTabBar:showingBadge:withTint:idiom:] + 1170
14  UIKit                               0x31001583 -[UITabBarItem(Static) _createViewForTabBar:showingBadge:idiom:] + 38
15  UIKit                               0x30ffd859 -[UITabBarItem(Static) _updateViewForIdiom:positionItems:] + 160
16  UIKit                               0x31004c43 -[UITabBar(Static) _configureItems:] + 406
17  UIKit                               0x310042db -[UITabBar(Static) _positionTabBarButtons:ignoringItem:] + 1234
18  UIKit                               0x3100133f -[UITabBar setItems:animated:] + 1358
19  UIKit                               0x31000d29 -[UITabBarController _rebuildTabBarItemsAnimated:] + 800
20  UIKit                               0x310051f9 -[UITabBarController _setSelectedViewController:] + 76
21  UIKit                               0x30eeb6e5 +[UIView(Animation) performWithoutAnimation:] + 72
22  UIKit                               0x31008bf7 -[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:] + 218
23  UIKit                               0x31008077 -[UITabBarController viewWillAppear:] + 134
24  UIKit                               0x30ef40eb -[UIViewController _setViewAppearState:isAnimating:] + 346
25  CoreFoundation                      0x2e6aff65 __53-[__NSArrayI enumerateObjectsWithOptions:usingBlock:]_block_invoke + 52
26  CoreFoundation                      0x2e6a994d -[__NSArrayI enumerateObjectsWithOptions:usingBlock:] + 220
27  UIKit                               0x30ef4265 -[UIViewController _setViewAppearState:isAnimating:] + 724
28  UIKit                               0x3106a4bf -[UINavigationController _startCustomTransition:] + 846
29  UIKit                               0x30f88273 -[UINavigationController _startDeferredTransitionIfNeeded:] + 418
30  UIKit                               0x30f8807d -[UINavigationController __viewWillLayoutSubviews] + 44
31  UIKit                               0x30f88015 -[UILayoutContainerView layoutSubviews] + 184
32  UIKit                               0x30ed9da3 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 346
33  QuartzCore                          0x30b60c6b -[CALayer layoutSublayers] + 142
34  QuartzCore                          0x30b5c47b CA::Layer::layout_if_needed(CA::Transaction*) + 350
35  QuartzCore                          0x30b5c30d CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 16
36  QuartzCore                          0x30b5bd1f CA::Context::commit_transaction(CA::Transaction*) + 230
37  QuartzCore                          0x30b5bb2f CA::Transaction::commit() + 314
38  QuartzCore                          0x30b5585d CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
39  CoreFoundation                      0x2e7321cd __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
40  CoreFoundation                      0x2e72fb71 __CFRunLoopDoObservers + 284
41  CoreFoundation                      0x2e72feb3 __CFRunLoopRun + 730
42  CoreFoundation                      0x2e69ac27 CFRunLoopRunSpecific + 522
43  CoreFoundation                      0x2e69aa0b CFRunLoopRunInMode + 106
44  GraphicsServices                    0x3336e283 GSEventRunModal + 138
45  UIKit                               0x30f3e049 UIApplicationMain + 1136
46  MyApp                               main (in MyApp) (main.m:16)
47  libdyld.dylib                       0x39340ab7 start + 2


Thread 0 Crashed:
0   libsystem_kernel.dylib              0x393f71fc __pthread_kill + 8
1   libsystem_c.dylib                   0x393a7ffd abort + 77
2   MyApp                               uncaught_exception_handler (in MyApp) + 27
3   CoreFoundation                      0x2e76724f __handleUncaughtException + 579
4   libobjc.A.dylib                     0x38e3890f _objc_terminate() + 175
5   libc++abi.dylib                     0x386ed1c7 std::__terminate(void (*)()) + 79
6   libc++abi.dylib                     0x386ecd2d __cxa_increment_exception_refcount + 1
7   libobjc.A.dylib                     0x38e387f7 objc_exception_rethrow + 43
8   CoreFoundation                      0x2e69ac9d CFRunLoopRunSpecific + 641
9   CoreFoundation                      0x2e69aa0b CFRunLoopRunInMode + 106
10  GraphicsServices                    0x3336e283 GSEventRunModal + 138
11  UIKit                               0x30f3e049 UIApplicationMain + 1136
12  MyApp                               main (in MyApp) (main.m:16)

【问题讨论】:

  • 您是否在应用中的任何位置使用此方法:replaceObjectsInRange:withObject:length:?
  • 不,所有内容都是从情节提要中加载的,我猜文本将设置为 UILabel 是一个 UITabBarItem 标题。
  • 你有机会解决这个问题吗?
  • 我已经做了很多内存优化来修复这样的崩溃,之后我没有在我的应用程序上看到这样的崩溃。这是因为加载标签栏(包含大量视图/视图控制器)时内存压力增加

标签: ios ipad storyboard uitabbarcontroller uitabbar


【解决方案1】:

来自你的崩溃日志,第 5 行

    5   UIKit                               0x30ee8ed7 -[NSAttributedString(UILabelAdditions) _ui_synthesizeAttributedSubstringFromRange:usingDefaultAttributes:] + 86

好像你根据

生成你的属性字符串
     - (NSAttributedString *)attributedSubstringFromRange:(NSRange)aRange

可能在该代码处设置一个断点,并检查您的字符串长度是否大于或等于该范围。

【讨论】:

  • 它是从情节提要添加到 UITabBarItem 标签的默认标题。
  • @atrane 我不知道你能不能提供一些代码sn-ps,这样对我们帮助你会更容易......
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-05
  • 1970-01-01
  • 1970-01-01
  • 2016-03-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多