ios - 如何在 UIKit 某处找到此崩溃的根源?

标签 ios objective-c uikit crashlytics

我一直收到来自 Crashlytics 的这种崩溃。它随时随机发生并且不可复制。我有一个堆栈跟踪指向 frame 属性中的 NaN 错误。但是我在我的代码中找不到这样的东西,而且没有线程包含我编写的代码,所以很难找到原因。

我附上了相同的堆栈跟踪。

`Fatal Exception: CALayerInvalidGeometry(CALayer position contains NaN: [nan 8])
0  CoreFoundation                 0x191066fe0 __exceptionPreprocess
1  libobjc.A.dylib                0x18fac8538 objc_exception_throw
2  CoreFoundation                 0x191066f28 -[NSException initWithCoder:]
3  QuartzCore                     0x194375acc CA::Layer::set_position(CA::Vec2<double> const&, bool)
4  QuartzCore                     0x194375c48 -[CALayer setPosition:]
5  QuartzCore                     0x194376198 -[CALayer setFrame:]
6  UIKit                          0x1977de83c __26-[_UILabelLayer setFrame:]_block_invoke
7  UIKit                          0x1977de6cc -[_UILabelLayer _setFrameOrBounds:settingAction:]
8  UIKit                          0x1977de7e8 -[_UILabelLayer setFrame:]
9  UIKit                          0x19718a7a8 -[UIView(Geometry) setFrame:]
10 UIKit                          0x19719a068 -[UILabel setFrame:]
11 UIKit                          0x19719b3bc -[UIView(Geometry) sizeToFit]
12 UIKit                          0x1972dc6ac -[UISegment _positionInfo]
13 UIKit                          0x19753b7d4 -[UISegment layoutSubviews]
14 UIKit                          0x19718e07c -[UIView(CALayerDelegate) layoutSublayersOfLayer:]
15 QuartzCore                     0x19437e274 -[CALayer layoutSublayers]
16 QuartzCore                     0x194372de8 CA::Layer::layout_if_needed(CA::Transaction*)
17 QuartzCore                     0x194372ca8 CA::Layer::layout_and_display_if_needed(CA::Transaction*)
18 QuartzCore                     0x1942ee34c CA::Context::commit_transaction(CA::Transaction*)
19 QuartzCore                     0x1943153ac CA::Transaction::commit()
20 UIKit                          0x1973ecbd8 _UIWindowUpdateVisibleContextOrder
21 UIKit                          0x1973ec9e8 +[UIWindow _prepareWindowsPassingTestForAppResume:]
22 UIKit                          0x1974285b0 -[UIApplication _handleApplicationActivationWithScene:transitionContext:completion:]
23 UIKit                          0x197427ef8 -[UIApplication _handleApplicationLifecycleEventWithScene:transitionContext:completion:]
24 UIKit                          0x1974134a8 __70-[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]_block_invoke
25 UIKit                          0x197413124 -[UIApplication scene:didUpdateWithDiff:transitionContext:completion:]
26 UIKit                          0x19774d7c8 -[UIApplicationSceneClientAgent scene:handleEvent:withCompletion:]
27 FrontBoardServices             0x192be222c __80-[FBSSceneImpl updater:didUpdateSettings:withDiff:transitionContext:completion:]_block_invoke.376
28 FrontBoardServices             0x192c0f884 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__
29 FrontBoardServices             0x192c0f6f0 -[FBSSerialQueue _performNext]
30 FrontBoardServices             0x192c0faa0 -[FBSSerialQueue _performNextFromRunLoopSource]
31 CoreFoundation                 0x19101542c __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
32 CoreFoundation                 0x191014d9c __CFRunLoopDoSources0
33 CoreFoundation                 0x1910129a8 __CFRunLoopRun
34 CoreFoundation                 0x190f42da4 CFRunLoopRunSpecific
35 GraphicsServices               0x1929ac074 GSEventRunModal
36 UIKit                          0x1971f6058 UIApplicationMain
37 XXXXXXXX                       0x1000550ac main (main.m:14)
38 libdyld.dylib                  0x18ff5159c start
` 

调整 UISegmentControl 的代码如下,这是非常古老的代码。到目前为止,一切正常。

    for (id segment in [SegmentControl subviews]) 
    {
        for (id label in [segment subviews]) 
        {
            if ([label isKindOfClass:[UILabel class]])
            {
                //hear u add any of delegate function to increase the height and other label functionality in this 
                [label setTextAlignment:NSTextAlignmentCenter];
//                [label setFont:[UIFont boldSystemFontOfSize:11]];
                [(UILabel *)label setNumberOfLines:2];
                //to adjust the label size manually with respect to text use below code
                [(UILabel *)label setLineBreakMode:NSLineBreakByWordWrapping];
                CGRect frame = [(UILabel *)label frame];
                frame.size = [(UIView *)segment frame].size; 
                frame.size.width = (SegmentControl.frame.size.width / [[[[self currentField] definition] listOfValues] count]) - 4;
                frame.origin.x = 2;
                frame.origin.y = 0;

                [(UILabel *)label setFrame:frame];
            }
        }           
    }

而且我的应用程序在专门执行此代码时从未崩溃。而且 listOfValues 永远不会为空。我对此深信不疑。

最佳答案

运行分析器:产品 -> 分析。 它会告诉你代码中不好的地方。 看起来你被零除了。

关于ios - 如何在 UIKit 某处找到此崩溃的根源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45350232/

相关文章:

uikit - iOS 7 : What is UIBarButtonItem's default font?

ios - 如何在点击 Swift4 时关闭 UIView

ios - 向从 Storyboard 构建的 UITableView 添加行

ios - 使用 block 会自动创建新线程吗?

ios - Swift:prepareForSegue 和 instantiateViewController 之间的区别

ios - FBSDKSharingDelegate 回调不起作用,即使发布工作正常

iphone - Calier子类问题

ios - 如何在 Swift 中更新 TableView 中的行数?

ios - 如何仅转义未转义的引号 Objective C

objective-c - Objective C xpath 获取多个标签值