2017-07-27 27 views
0

我一直在接受Crashlytics的這種崩潰。它隨機發生,不可重複。我有一個堆棧跟蹤,指向框架屬性中的NaN錯誤。但在我的代碼中找不到像這樣的東西,也沒有任何線程包含我寫的代碼,所以很難找到這個原因。如何在UIKit某處找到此崩潰的根目錄?

我附上相同的堆棧跟蹤。

`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永遠不會是空的。我確信這一點。

+1

你計算一個框架的地方嗎?也許你除以零。 –

+1

您的應用在恢復應用時嘗試佈置'UISegmentedControl',並且由於位置無效而崩潰。看起來你的視圖層次結構出了問題。在崩潰之前,您的視圖層次結構可能已經處於不良狀態。搜索你的控制檯警告。 – Sulthan

+0

入住此課程'FrontBoardServices' –

回答

0

運行分析器:產品 - >分析。 它會顯示代碼中的不良位置。 看起來像你有零除。

0

既然你有NaN問題,你已經劃分了零。據我所知,你只在這裏進行占卜操作,檢查不同情況下的分母,你會發現解決方案:

frame.size.width =(SegmentControl.frame.size.width/[[[[self currentField] definition] listOfValues] count]) - 4;