Ios [\uu NSArrayM objectAtIndex:]:索引1超出空数组的界限'

Ios [\uu NSArrayM objectAtIndex:]:索引1超出空数组的界限',ios,uitableview,nsarray,Ios,Uitableview,Nsarray,我的应用程序在模拟器6.1上运行良好,但在7.0上崩溃 以下是崩溃日志: [__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array' *** First throw call stack: ( 0 CoreFoundation 0x024595e4 __exceptionPreprocess + 180 1 libobjc.A.dylib

我的应用程序在模拟器6.1上运行良好,但在7.0上崩溃

以下是崩溃日志:

[__NSArrayM objectAtIndex:]: index 1 beyond bounds for empty array'
*** First throw call stack:
(
    0   CoreFoundation                      0x024595e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x021dc8b6 objc_exception_throw + 44
    2   CoreFoundation                      0x023fa556 -[__NSArrayM objectAtIndex:] + 246
    3   OHUM                                0x0003c9b7 -[PatientSelectionViewCon tableView:cellForRowAtIndexPath:] + 503
    4   UIKit                               0x00cdcd2f -[UITableView _createPreparedCellForGlobalRow:withIndexPath:] + 412
    5   UIKit                               0x00cdce03 -[UITableView _createPreparedCellForGlobalRow:] + 69
    6   UIKit                               0x00cc103c -[UITableView _updateVisibleCellsNow:] + 2146
    7   UIKit                               0x00cbf531 -[UITableView _updateVisibleCellsImmediatelyIfNecessary] + 66
    8   UIKit                               0x00ccd26f -[UITableView _visibleCells] + 35
    9   UIKit                               0x00ccd2c4 -[UITableView visibleCells] + 33
    10  UIKit                               0x00cc65c2 -[UITableView _updateAnimationDidStop:finished:context:] + 1484
    11  UIKit                               0x00cc5da9 __46-[UITableView _updateWithItems:updateSupport:]_block_invoke762 + 90
    12  UIKit                               0x00c50b75 -[UIViewAnimationBlockDelegate _didEndBlockAnimation:finished:context:] + 306
    13  UIKit                               0x00c3a81c -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 267
    14  UIKit                               0x00c3ab04 -[UIViewAnimationState animationDidStop:finished:] + 80
    15  QuartzCore                          0x00a41e84 _ZN2CA5Layer23run_animation_callbacksEPv + 304
    16  libdispatch.dylib                   0x027f14b0 _dispatch_client_callout + 14
    17  libdispatch.dylib                   0x027df766 _dispatch_main_queue_callback_4CF + 340
    18  CoreFoundation                      0x024bea5e __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
    19  CoreFoundation                      0x023ff72b __CFRunLoopRun + 1963
    20  CoreFoundation                      0x023feb33 CFRunLoopRunSpecific + 467
    21  CoreFoundation                      0x023fe94b CFRunLoopRunInMode + 123
    22  GraphicsServices                    0x044949d7 GSEventRunModal + 192
    23  GraphicsServices                    0x044947fe GSEventRun + 104
    24  UIKit                               0x00bee94b UIApplicationMain + 1225
    25  OHUM                                0x00021fed main + 141
    26  libdyld.dylib                       0x02a81725 start + 0
)
libc++abi.dylib: terminating with uncaught exception of type NSException
方法是:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PatientListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    cell.delegate = self;

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if(indexPath.row == selectedIndex.row){

        //Hide all previous dropdown items.
        [self removePreviousDropDownItems];

        cell.isExpanded = YES;


    }
    else {

        cell.isExpanded = NO;

    }
     // I check the Array here
     if([self.objPatientSelectionVO.arrPatientVO count]==0)
    {
        return cell;
    }

    PatientVO * objVO = [self.objPatientSelectionVO.arrPatientVO objectAtIndex:indexPath.row];

    [cell setupData:objVO];

    cell.tag = indexPath.row;


    //Sets the size of the drop down depending on the expanded state of the Cell.
    [cell handleExpansion];
    return cell;
}
此数组为空 self.objPatientSelectionVO.arrvatientvo

如果这是填充数据的主数组。。。然后,您需要在numberOfRows方法中返回数组的计数

- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
是空的。确保在创建tableView之前添加了对象。您已从数组中删除索引

以及:


请发布您的cellForRowAtIndexPath方法。@Kuldeep Rajput:您需要做一些基本的调试。在执行objectAtIndex之前,请记录self.objPatientSelectionVO.arrPatientVO数组和indexPath.row的计数。在某些情况下,indexPath.row必须超过count-1。然后对阵列的填充或设置位置进行日志记录和调试。继续回溯,直到达到iOS 7和iOS 6中行为不同的点。简单地说:调试NSLog,逐步完成设置阵列的代码,等等。嗨,Anna,我解决了这个问题:Thanx,但应用程序仍然崩溃。这个应用程序在ios 6 ipad上运行良好,但当我试图在ios 7设备上运行的同一版本崩溃时,是否存在API问题或其他问题
self.objPatientSelectionVO.arrPatientVO 
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section{
   return self.objPatientSelectionVO.arrPatientVO.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    PatientListCell * cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

    cell.delegate = self;

    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    if(indexPath.row == selectedIndex.row){

        //Hide all previous dropdown items.
        [self removePreviousDropDownItems];

        cell.isExpanded = YES;


    }
    else {

        cell.isExpanded = NO;

    }
    //This check for Array is empty then return cell
    if([self.objPatientSelectionVO.arrPatientVO count]==0)
    {
        return cell;
    }


    PatientVO * objVO = [self.objPatientSelectionVO.arrPatientVO objectAtIndex:indexPath.row];

    [cell setupData:objVO];

    cell.tag = indexPath.row;


    //Sets the size of the drop down depending on the expanded state of the Cell.
    [cell handleExpansion];
    return cell;
}