2014-09-29 83 views
-1

我們這沒有任何問題的工作中的iOS 7的應用程序,但在iOS 8運行時,出現以下錯誤崩潰:UIPickerView拋出 - [__ NSArrayM objectAtIndex:]:索引0超出界限時,數據源是不是在iOS的空8

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -  [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' 

    *** First throw call stack: 

    (

0 CoreFoundation      0x03361df6 __exceptionPreprocess + 182 

1 libobjc.A.dylib      0x026fca97 objc_exception_throw + 44 

2 CoreFoundation      0x03238073 -[__NSArrayM objectAtIndex:] + 243 

3 eAlth Devel       0x0022f13e -[NSArray(TKCategory) firstObject] + 62 

4 UIKit        0x00f411ee -[UITableView reloadData] + 443 

5 UIKit        0x00f45ede -[UITableView _reloadDataIfNeeded] + 78 

6 UIKit        0x00f4bec7 -[UITableView layoutSubviews] + 36 

7 UIKit        0x00ec19c0 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 608 

8 libobjc.A.dylib      0x02712771 -[NSObject performSelector:withObject:] + 70 

9 QuartzCore       0x0055a27f -[CALayer layoutSublayers] + 152 

10 QuartzCore       0x0054e105 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 397 

11 QuartzCore       0x0054df60 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26 

12 QuartzCore       0x004ac676 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 284 

13 QuartzCore       0x004ada3c _ZN2CA11Transaction6commitEv + 392 

14 QuartzCore       0x004ae108 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92 

15 CoreFoundation      0x03284fbe __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30 

16 CoreFoundation      0x03284f00 __CFRunLoopDoObservers + 400 

17 CoreFoundation      0x0327a93a __CFRunLoopRun + 1226 

18 CoreFoundation      0x0327a1ab CFRunLoopRunSpecific + 443 

19 CoreFoundation      0x03279fdb CFRunLoopRunInMode + 123 

20 GraphicsServices     0x04aa924f GSEventRunModal + 192 

21 GraphicsServices     0x04aa908c GSEventRun + 104 

22 UIKit        0x00e36e16 UIApplicationMain + 1526 

23 eAlth Devel       0x000f1c5c main + 76 

24 libdyld.dylib      0x02a53ac9 start + 1 

25 ???         0x00000001 0x0 + 1 

) 

    libc++abi.dylib: terminating with uncaught exception of type NSException 

其錯誤之前調用的方法是:

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row  forComponent:(NSInteger)component{ 

     NSObject * sel = [pickerData objectAtIndex:row]; 

     return sel.description; 

    } 

pickerData陣列對象不是零,它在它已下列對象:

self->pickerData: 

    <__NSArrayM 0x7c130080>(

    All, 

    Br Clinic, 

    Clinic 2, 

    EssHth, 

    GC Clinic, 

    HHolistics, 

    K5003 - HHD3112, 

    K5003 - HHD3112 - Gp2, 

    NEW DEMO CLINIC, 

    Nursing Home Visits, 

    PR Accupuncture, 

    PP, 

    RB Therapy, 

    SC Clinic, 

    S Clinic, 

    TW Practice 

    ) 

關於如何解決該問題的任何建議? 在此先感謝!

+0

您試圖索引的數組* *爲空。如果你在嘗試索引操作之前NSLog它,你會看到。 – 2014-09-29 01:15:43

+0

很明顯,你沒有閱讀我寫的答案! 只有我在代碼中改變的東西在答案中提到! – chamalabey 2014-10-03 05:56:43

+0

然後很明顯,當你跨過你所說的聲明時,問題不會發生。 – 2014-10-03 11:04:28

回答

2

請參考我的問題的以下行。

3 eAlth Devel       0x0022f13e -[NSArray(TKCategory) firstObject] + 62 

在iOS系統中8蘋果已經實施了

- (id)firstObject 

但是我在我的項目中使用的正在實施的NSArray上述方法的分類庫的一個方法。我使用的圖書館是TapkuLibrary。

當發起UIPickerView,iOS的迷糊將要使用的哪個「firstObject」的方法。它來自核心庫還是來自TapkuLibrary的庫。

由於該應用程序崩潰。

例外情況不明確,我想出來。一位專家在他如此例外之後指出我正確的方向。 (謝謝專家!你救我頭三天刮傷!)

任何如何,如果你在iOS的8得到了類似的異常,檢查是否有一個「類別」的NSArray。

解決方法是從項目中刪除的類別,如果只實現了「firstObject」的方法。 希望這有助於。

相關問題