UITableView _endCellAnimationsWithContext中的断言失败

时间:2014-05-02 12:33:13

标签: ios objective-c uitableview didselectrowatindexpath

我遇到这样的问题:

我在从日期选择器中选择日期后将一些数据加载到表视图中。我想要加载的数据被加载到didSelectRowAtIndexPath方法内的变量中。当表检查行数时,它检查该变量的计数是否大于零等等。

我的问题是:当我通过调用Web服务[使用AFNetworking库]将数据加载到变量时,它运行良好。但是当我直接得到数据[我已经实现了一个方法来在表加载之前调用Web服务,并通过一个方法保存数据]它会给出这个错误

   Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-2903.23/UITableView.m:1330                                       

2014-05-02 17:25:12.665 varrdle_v2 [1428:a0b] *由于未捕获的异常而终止应用 NSInternalInconsistencyException',原因:'无效更新:第0节中的行数无效。更新后的现有部分中包含的行数(3)必须等于该部分中包含的行数更新(2),加上或减去从该部分插入或删除的行数(插入0,删除1),加上或减去移入或移出该部分的行数(0移入,0移出) 。 * 首先抛出调用堆栈:

我无法弄清楚为什么会这样。唯一不同的是我采用数据的方式。

下面是我的实现

行数

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
 {


NSArray* reqFdate= [TableViewController getrequestPerDate];
NSLog(@"Count OF REQUESTS: %d",reqFdate.count);
if (reqFdate.count == 0 ) {
    NSInteger numberOfRows = [self.persons count];

    if ([self datePickerIsShown]){

        numberOfRows++;

    }
    NSLog(@"NO OF ROWS in IF %d",numberOfRows);
    return numberOfRows;
}
else{
    NSLog(@"NO OF ROWS %d",reqFdate.count);
    return reqFdate.count;
}
   }

索引路径行的单元格

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  {

UITableViewCell *cell;

NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// display in 12HR/24HR (i.e. 11:25PM or 23:25) format according to User Settings
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
NSString *currentTime = [dateFormatter stringFromDate:today];
NSDate *date=[dateFormatter dateFromString:currentTime];



if(indexPath.row==0){
    VCPerson *person = self.persons[0];

    cell = [self createPersonCell:person];

}



else if ([self datePickerIsShown] && (self.datePickerIndexPath.row == 1)){

    // VCPerson *person = self.persons[indexPath.row -1];



    cell = [self createPickerCell:date];

}

else{

    TacleCell *cell = (TacleCell*)[self.tableView dequeueReusableCellWithIdentifier:otherCellID];
    cell.delegate = self;


    if(cell == nil)
    {
        cell = [[TacleCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:otherCellID];
    }


    else
    {
        //cancel loading previous image for cell
        [[AsyncImageLoader sharedLoader] cancelLoadingImagesForTarget:cell.profileImage];
    }



    return cell;
}

return cell;

}

didSelect方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {


    [self.tableView beginUpdates];

    int countOfRowss = [TableViewController getrequestPerDate].count;
    if(countOfRowss>0)
    {
    NSArray* indexpathsArry = [self getIndexPaths];

    [self.tableView deleteRowsAtIndexPaths:indexpathsArry withRowAnimation:YES];
    requestForDate = nil;

    }

    if ([self datePickerIsShown] && (self.datePickerIndexPath.row - 1 == indexPath.row)){

        [self hideExistingPicker];
        //[self.tableView reloadData];
        //[self viewDidLoad];

        //call the service and take the results



        NSString* selecteDate = [TableViewController getDate];

        //NSString* prsonID =[LoginView getPersonID];


       //  here i call this method and get the data.
        requestForDate= [self filterRequestForDate:selecteDate];
        NSLog(@"FILTERED REQUESTS :%@",requestForDate);

        //requestForDate = nil;
        [self.tableView reloadData];





       // NSString* selecteDate = [ScheduleView getDate];



    //  this is how i fetch the data by using a web service
       /* NSString* prsonID =[LoginView getPersonID];

        NSDictionary* parms = [NSDictionary dictionaryWithObjectsAndKeys:prsonID,@"caregiverPersonId",selecteDate,@"selectedDate", nil];

        jsonpaser* jp = [[jsonpaser alloc]init];
        //[self.indicator_process startAnimating];
        [jp getWebServiceResponce:@"myUrl" :parms success:^(NSDictionary *responseObject)
         {



             requestForDate = responseObject;
             NSLog(@"RESPONSEFORDATE_IN DIDSELECT :%@",requestForDate);
             NSArray* indexpaths = [self getIndexPaths];
             NSLog(@"indexPATHS %@",indexpaths);
             //[self.indicator_process stopAnimating];
             //[_dimmingView removeFromSuperview];
             [self.tableView reloadData];

         }];

        */

        }

    else{

        //--

        NSIndexPath *newPickerIndexPath = [self calculateIndexPathForNewPicker:indexPath];

        if ([self datePickerIsShown]){

            [self hideExistingPicker];


        }

        [self showNewPickerAtIndex:newPickerIndexPath];



        self.datePickerIndexPath = [NSIndexPath indexPathForRow:newPickerIndexPath.row + 1 inSection:0];
        NSLog(@"DATEPICKERINDEX %@",self.datePickerIndexPath);


        //self.datePickerIndexPath = nil;



    }

    // this is the line where a row deleted
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

    [self.tableView endUpdates];


 }

请有人告诉我问题在哪里......

谢谢

1 个答案:

答案 0 :(得分:2)

关于Apple文档apple link,您不应在reloadDatabeginUpdates之间致电endUpdates

您应该移除beginUpdatesendUpdates或将reloadData移到群组外。