2014-09-29 59 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”的方法。 希望这有助于。

相关问题