Ios 打电话到'时应用程序崩溃;tableView EndUpdate';

Ios 打电话到'时应用程序崩溃;tableView EndUpdate';,ios,objective-c,uitableview,didselectrowatindexpath,Ios,Objective C,Uitableview,Didselectrowatindexpath,我目前正在UITableViewCell内部开发一个实现 当我选择单元格应该插入的正上方的单元格时,我可以显示和隐藏该选择器单元格,这是我所期望的行为。但是,如果我在表视图中选择任何其他单元格,应用程序将崩溃: *** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:1582 在查看之后,我添加了一个

我目前正在UITableViewCell内部开发一个实现

当我选择单元格应该插入的正上方的单元格时,我可以显示和隐藏该选择器单元格,这是我所期望的行为。但是,如果我在表视图中选择任何其他单元格,应用程序将崩溃:

*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:1582
在查看之后,我添加了一个异常断点,我发现应用程序在调用
[tableView EndUpdate]时崩溃
中选择行索引路径

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

    // Check to see if the "Only Alert From" row was selected. The cell with the picker should be below this one.
    if (indexPath.section == TimeOfDaySection && indexPath.row == HourTimeZoneRow  && self.timePickerIsShowing == NO){

        [tableView beginUpdates];
        [self showTimePicker];
        [tableView endUpdates];

    } else{
        [tableView beginUpdates];
        [self hideTimePicker];
        [tableView endUpdates];
        [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}
也就是说,我不知道如何继续。如果我注释掉对
[tableView endUpdates]的调用,当选择其他单元格时,应用程序不会崩溃,但具有选择器视图的单元格不会隐藏。有人有什么建议吗?谢谢大家!

编辑:下面是我的
showTimePicker
hideTimePicker
代码:

- (void)showTimePicker
{
    self.timePickerIsShowing = YES;
    self.timePicker.hidden = NO;

    //Create the index path where we insert the cell with the picker
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:HourTimeZoneRow + 1 inSection:TimeOfDaySection];

    [self.tableView beginUpdates];
    [self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    [self.tableView endUpdates];

    self.timePicker.alpha = 0.0f;
    [UIView animateWithDuration:0.25 animations:^{
        self.timePicker.alpha = 1.0f;
        //This is the row where the picker cell should be inserted
        [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:HourTimeZoneRow + 1 inSection:TimeOfDaySection]] withRowAnimation:UITableViewRowAnimationFade];
        [self.tableView reloadData];
    }];
}

- (void)hideTimePicker {
    self.timePickerIsShowing = NO;
    self.timePicker.hidden = YES;

    //Create the index path where we delete the cell with the picker
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:HourTimeZoneRow + 1 inSection:TimeOfDaySection];
    [self.tableView beginUpdates];
    //Delete the picker row
    [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    [self.tableView endUpdates];
    [UIView animateWithDuration:0.25
                     animations:^{
                         self.timePicker.alpha = 0.0f;
                     }
                     completion:^(BOOL finished){
                         self.timePicker.hidden = YES;
                     }];
}
编辑2:阅读后,我相信问题可能出在我的
numberOfRowsInSection
方法上:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    switch (section) {
        case NotificationsSection:
            return TotalPreferencesRows;
            break;
        case RedZoneSection:
            return TotalRedZoneRows;
            break;
        case TimeOfDaySection:
            if (self.timePickerIsShowing) {
                return TotalTimeOfDayRows + 1;
            }
//            else if (self.timePickerIsShowing == NO){
//                return TotalTimeOfDayRows;
//            }
            else{
                return TotalTimeOfDayRows;
            }
            return TotalTimeOfDayRows;
            break;
        default:
            return 0;
            break;
    }
}

不确定这是否是崩溃的原因,但不建议您在中多次调用BeginUpdate
[tableView开始更新];
[自动显示时间选择器];
[tableView EndUpdate]

因为showTimePicker调用
[self.tableView BeginUpdate]

问题出在didSelectRowAtIndexPath中,您调用了hide方法,即使它可能没有显示出来。将
else
子句设置为
else if
,如下所示:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];

    // Check to see if the "Only Alert From" row was selected. The cell with the picker should be below this one.
    if (indexPath.section == TimeOfDaySection && indexPath.row == HourTimeZoneRow  && self.timePickerIsShowing == NO){

        [tableView beginUpdates];
        [self showTimePicker];
        [tableView endUpdates];

    } else if (indexPath.section == TimeOfDaySection && indexPath.row == HourTimeZoneRow  && self.timePickerIsShowing == YES){
        [tableView beginUpdates];
        [self hideTimePicker];
        [tableView endUpdates];
        [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
    }
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

您可以发布显示/隐藏时间选择器方法的代码吗?这将有助于看到你如何显示时间选择器当然,我道歉!请出示事故日志。另外,添加一个异常断点以显示崩溃的位置。你好@Fogmeister,谢谢,我将发布崩溃日志。我添加了一个异常断点;我将对我的问题进行编辑以使其更清楚。谢谢Kim,我刚刚在“DidSelectRowatineXpath”中发出了“正在和结束更新”的呼叫,但这次崩溃发生在对“[tableView endUpdates]”的呼叫上在“hideTimePicker”中只是为了确定:您是否在DidSelectRowatinexPath中进行了所有开始/结束更新的调用?还有
[self hideTimePicker]周围的代码?是的,我在didSelectRowAtIndexPath中完成了所有开始/结束更新的调用。这些调用只存在于我的show/hideTimePicker方法中。你能发布引发的异常吗?似乎是这样:**Assertion failure in-[UITableView\u endCellAnimationsWithContext:,/SourceCache/UIKit\u Sim/UIKit-3318.16.14/UITableView.m:1582