Xcode 当iOS 8中的数据源不为空时,UIPickerView抛出-[\uuu nsarray-objectAtIndex:]:索引0超出边界

Xcode 当iOS 8中的数据源不为空时,UIPickerView抛出-[\uuu nsarray-objectAtIndex:]:索引0超出边界,xcode,ios8,uipickerview,Xcode,Ios8,Uipickerview,我们有一款应用程序,在iOS 7中运行时不会出现任何问题,但在iOS 8上运行时会出现以下错误: *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** - [__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array' *** First throw call stack: (

我们有一款应用程序,在iOS 7中运行时不会出现任何问题,但在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数组对象不是nil,其中包含以下对象:

    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

    )
self->pickerData:
(
全部的
Br诊所,
诊所2,
埃施特,
GC诊所,
H政治学,
K5003-HHD3112,
K5003-HHD3112-Gp2,
新示范诊所,
护理家访,
针灸,
PP,
RB疗法,
SC诊所,
医生诊所,
TW实践
)
有没有关于如何解决这个问题的建议?
提前谢谢

请参考我问题的下一行

3   eAlth Devel                         0x0022f13e -[NSArray(TKCategory) firstObject] + 62
在iOS 8中,苹果已经实现了

- (id)firstObject
但我在项目中使用的一个库是使用上述方法实现NSArray的一个类别。我正在使用的图书馆是塔库图书馆

在启动UIPickerView时,iOS会对要使用的“firstObject”方法感到困惑。它是来自核心库还是来自Tapku库

由于该应用程序崩溃

例外情况对我来说并不清楚。一位专家给我指出了正确的方向。(谢谢专家!你又帮我省去了三天的挠头!)

如果您在iOS 8中遇到类似的异常,请检查您是否有NSArray的“类别”

补救方法是,如果类别只实现“firstObject”方法,则从项目中删除该类别。
希望这能有所帮助。

您尝试索引的数组为空。如果您在尝试索引操作之前记录它,您将看到。很明显,您没有阅读我写的答案!答案中提到了我在代码中更改的唯一内容!很明显,当你跨过你正在调用的语句时,问题并没有发生。我该如何在我没有源代码的地方设置一个断点?显然,你有这个方法。你怎么知道有人叫它?