2016-02-05 60 views
0

當我試圖通過Xcode6.4使用它時,UITableView工作的很好,但是當我試着通過Xcode 7.1.1崩潰。我想這是因爲iOS版本。我附上了崩潰日誌。請提出解決問題的最佳方法。我很肯定: 1)數據源和代表工作正常。 2)Numberofrows和heightOfRow方法也被調用,但它在cellForRowAtIndexPath被調用之前崩潰。UitableView在iOS8.4(Xcode 6.4)上正常工作,但在iOS9.1上崩潰(Xcode 7.1.1)

這裏是日誌:

2016年2月5日15:34:27.400 Autograph24 [3720:87023] *斷言故障 在 - [UITableViewRowData _assertValidIndexPath:allowEmptySection:], /buildroot的/ Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UITableViewRowData.m:2310 2016-02-05 15:34:27.506 Autograph24 [3720:87023] *終止應用程序 由於未捕獲異常'NSInternalInconsistencyException',原因: 'IndexPath'無效 ***第一次拋出調用堆棧:(0 CoreFo undation 0x00000001075c9f45 exceptionPreprocess + 165 1 libobjc.A。dylib
0x0000000107956deb objc_exception_throw + 48 2的CoreFoundation
0x00000001075c9daa + [NSException提高:格式:參數:] + 106 3
基金會0x0000000106e9b5ee - [NSAssertionHandler handleFailureInMethod:對象:文件:LINENUMBER:描述:] + 198 4
的UIKit 0x0000000108d11412 - [UITableViewRowData _assertValidIndexPath:allowEmptySection:] + 963 5的UIKit 0x0000000108d11465 - [UITableViewRowData ensureHeightsFaultedInForIndexPath:availHeight:edgeInset:的scrollPosition:] + 55 6的UIKit 0x0000000108af50c6 - [UITableView的_contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:] + 2510 7的UIKit 0X 0000000108af59b9 - [UITableView的scrollToRowAtIndexPath:atScrollPosition:動畫:] + 39 8 Autograph24 0x0000000106b1b2ad - [DashboardVC scrollToToday] + 685 9 Autograph24 0x0000000106b20289 - [DashboardVC changeCalendarStyle] + 313 10 Autograph24 0x0000000106b20144 - [DashboardVC resizeScreenForPortrait] + 788 11 Autograph24
0x0000000106b1f6a0 - [DashboardVC rotateScreen] + 176 12 Autograph24 0x0000000106b15e76 - [DashboardVC viewDidLoad中] + 166 13的UIKit
0x0000000108b49cc4 - [UIViewController中loadViewIfRequired] + 1198 14 的UIKit 0x0000000108b4fc7b - [UIViewController中__viewWillAppear:] + 120 15的UIKit 0x0000000108b7fa37 - [ ü INavigationController _startCustomTransition:] + 1203 16的UIKit 0x0000000108b8fcdb - [UINavigationController的_startDeferredTransitionIfNeeded:] + 712 17的UIKit 0x0000000108b90cea - [UINavigationController的__viewWillLayoutSubviews] + 57 18的UIKit 0x0000000108d36c85 - [UILayoutContainerView layoutSubviews] + 248 19 的UIKit 0x0000000108a6be40 - [UIView的(CALayerDelegate )layoutSublayersOfLayer:] + 710 20 QuartzCore 0x000000010736359a - [CALayer的 layoutSublayers] + 146 21 QuartzCore
0x0000000107357e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 22 QuartzCore 0x0000000107357cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 23 QuartzCore 0x000000010734c475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 24 QuartzCore 0x0000000107379c0a _ZN2CA11Transaction6commitEv + 486 25 QuartzCore 0x000000010737a37c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 26的CoreFoundation 0x00000001074f5947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION
+ 23 27的CoreFoundation 0x00000001074f58b7 __CFRunLoopDoObservers + 391 28的CoreFoundation 0x00000001074eb50b __CFRunLoopRun + 1147 29的CoreFoundation
0x00000001074eae08 CFRunLoopRunSpecific + 488 30 GraphicsServices
0x000000010b1b5ad2 GSEventRunModal + 161 31 UIKit
0x00000001089b730d UIApplicationMain + 171 32 Autograph24
0x0000000106b15d9f主+ 111 33 libdyld.dylib
0x000000010aac192d啓動+ 1 34 ???
0x0000000000000001爲0x0 + 1)的libC++ abi.dylib:與類型NSException

+0

是否設置了numberOfSection和viewForHeader? –

+0

它已經在崩潰日誌中聲明: - 由於未捕獲的異常'NSInternalInconsistencyException',原因:'無效的indexPath'終止應用程序。 – Vizllx

回答

0

您有一個無效indexpath的 未捕獲的異常終止。這意味着部分或行或兩者都不正確。如果你有一個包含2部分和每部分2行的表,那麼索引路徑0-3是無效的,因爲部分0不提供第3行。同樣,索引路徑2-1也是無效的,因爲第2部分不存在(只有0和1)。

至於如何解決這個問題,首先檢查是否所有必需的方法都被調用並且您的數據被正確初始化。然後在你的班級周圍撒點斷點。主要在哪裏使用任何類型的索引路徑,並查看它嘗試從數據外部讀取的位置。

0

學會閱讀崩潰日誌。在大多數情況下,當然在這種情況下,它們所包含的所有相關信息:

2016-02-05 15:34:27.400 Autograph24[3720:87023] * Assertion failure in -[UITableViewRowData _assertValidIndexPath:allowEmptySection:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UITableViewRowData.m:2310 
2016-02-05 15:34:27.506 Autograph24[3720:87023] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid indexPath' 

上面清清楚楚地寫着:原因:「無效indexPath」

所以第一個暗示:一個無效的索引路徑(這是一個衆所周知的事情,如果你使用UITableViews)參與。

接下來是跟蹤發生錯誤的堆棧跟蹤。前幾個堆棧位置在Apple的代碼中。通常跳過它們。但偶爾,它們包含有趣的提示。這裏有一個功能assertValidIndexPath:allowEmptySection:。這再次表明索引路徑是問題。

*** First throw call stack: (
0 CoreFoundation 0x00000001075c9f45 exceptionPreprocess + 165 
1 libobjc.A.dylib 0x0000000107956deb objc_exception_throw + 48 
2 CoreFoundation 0x00000001075c9daa +[NSException raise:format:arguments:] + 106 
3 Foundation 0x0000000106e9b5ee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198 
4 UIKit 0x0000000108d11412 -[UITableViewRowData _assertValidIndexPath:allowEmptySection:] + 963 
5 UIKit 0x0000000108d11465 -[UITableViewRowData ensureHeightsFaultedInForIndexPath:availHeight:edgeInset:scrollPosition:] + 55 
6 UIKit 0x0000000108af50c6 -[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:] + 2510 
7 UIKit 0x0000000108af59b9 -[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:] + 39 

在這裏你的代碼如下。看看上面和下面的行。它說你的功能[DashboardVC scrollToToday]已經調用功能[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]。這是您的代碼中觸發錯誤的地方。

8 Autograph24 0x0000000106b1b2ad -[DashboardVC scrollToToday] + 685 
9 Autograph24 0x0000000106b20289 -[DashboardVC changeCalendarStyle] + 313 
10 Autograph24 0x0000000106b20144 -[DashboardVC resizeScreenForPortrait] + 788 
11 Autograph24 0x0000000106b1f6a0 -[DashboardVC rotateScreen] + 176 
12 Autograph24 0x0000000106b15e76 -[DashboardVC viewDidLoad] + 166 

這是下一個有趣的位置。這裏蘋果的UIKit叫你[DashboardVC viewDidLoad]。所以這給了很多背景。它在viewDidLoad階段的建設中早期發生。

13 UIKit 0x0000000108b49cc4 -[UIViewController loadViewIfRequired] + 1198 
14 UIKit 0x0000000108b4fc7b -[UIViewController __viewWillAppear:] + 120 
15 UIKit 0x0000000108b7fa37 -[UINavigationController _startCustomTransition:] + 1203 
16 UIKit 0x0000000108b8fcdb -[UINavigationController _startDeferredTransitionIfNeeded:] + 712 
17 UIKit 0x0000000108b90cea -[UINavigationController __viewWillLayoutSubviews] + 57 
18 UIKit 0x0000000108d36c85 -[UILayoutContainerView layoutSubviews] + 248 
19 UIKit 0x0000000108a6be40 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 710 
20 QuartzCore 0x000000010736359a -[CALayer layoutSublayers] + 146 
21 QuartzCore 0x0000000107357e70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 
22 QuartzCore 0x0000000107357cee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 
23 QuartzCore 0x000000010734c475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 
24 QuartzCore 0x0000000107379c0a _ZN2CA11Transaction6commitEv + 486 
25 QuartzCore 0x000000010737a37c _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 
26 CoreFoundation 0x00000001074f5947 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23 
27 CoreFoundation 0x00000001074f58b7 __CFRunLoopDoObservers + 391 
28 CoreFoundation 0x00000001074eb50b __CFRunLoopRun + 1147 
29 CoreFoundation 0x00000001074eae08 CFRunLoopRunSpecific + 488 
30 GraphicsServices 0x000000010b1b5ad2 GSEventRunModal + 161 
31 UIKit 0x00000001089b730d UIApplicationMain + 171 
32 Autograph24 0x0000000106b15d9f main + 111 
33 libdyld.dylib 0x000000010aac192d start + 1 
34 ??? 0x0000000000000001 0x0 + 1) libc++abi.dylib: 
terminating with uncaught exception of type NSException 

結合這個信息,我可以得出結論,你[DashboardVC viewDidLoad],這勢必內調用[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]失敗,任何索引路徑,因爲UITableView沒有正確此時視圖控制器生命週期的構建。

早期的iOS版本在這裏比較寬鬆;但後來的版本對視圖控制器完全構建之前可以執行的操作有相當的限制。

您需要將[UITableView scrollToRowAtIndexPath:atScrollPosition:animated:]電話轉至viewWillAppear:甚至viewDidAppear:

相關問題