如果删除第一部分-应用程序崩溃

亚历克斯·威尔洛克

如果我删除自己部分中的最后一个单元格,则需要删除部分

如果我删除以结尾开头的部分-效果很好,但是如果我删除第一部分-应用程序崩溃

和我的最后一部分-添加按钮

怎么了 ?

我的代码

- (void)deleteExerciseFromCustomTable:(NSIndexPath *)indexPath {
    [[_exercises objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];

    [_previewTable beginUpdates];
    [_previewTable deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
    [_previewTable endUpdates];

    if ([[_exercises objectAtIndex:indexPath.section] count] == 0) {
        [_group removeObjectAtIndex:indexPath.section];
        [_previewTable beginUpdates];
        [_previewTable deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationRight];
        [_previewTable endUpdates];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == [_group count]) {
        return 1;
    }else{
        return [[_exercises objectAtIndex:section] count];
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [_group count] + 1;
}
亚历克斯·威尔洛克

我解决了我的问题

 - (void)deleteExerciseFromCustomTable:(NSIndexPath *)indexPath {

    if ([[_exercises objectAtIndex:indexPath.section] count] == 1) {
        [_group removeObjectAtIndex:indexPath.section];
        [_exercises removeObjectAtIndex:indexPath.section];        
        [_previewTable beginUpdates];
        [_previewTable deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
        [_previewTable deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationRight];
        [_previewTable endUpdates];

    }else{
        [[_exercises objectAtIndex:indexPath.section] removeObjectAtIndex:indexPath.row];            
        [_previewTable beginUpdates];
        [_previewTable deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];        
        [_previewTable endUpdates];        

    }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

应用程序在网格布局声明的一部分中崩溃

Bash-在“:”上分割命令的结果,并用第一部分调用程序

在代码的第一部分之后程序没有继续

在 iteritem 中的每个项目的 Pandas 数据帧上应用正则表达式并仅返回第一部分

我应该如何处理这个程序?我用 AND 尝试了第一部分并写了 3 个 if 语句

删除路径的第一部分?

删除网址的第一部分

应用程序层协议是系统实用程序的一部分吗?

如果应用程序崩溃,执行代码?

C ++应用程序在删除时崩溃

当前台的应用程序发生内存不足崩溃时,将调用App Delegate生命周期的哪一部分?

Identity Server作为Web API或单独应用程序的一部分

是Meteor应用程序中的$ or Mongo的一部分吗?

使用子域访问Web应用程序的一部分(Symfony)

使用Angle 4作为现有Web应用程序的一部分

触发Spring Batch作为Web应用程序的一部分

如何覆盖“应用程序管道的一部分”内部名称?

不将图像存储为应用程序的一部分

创建指向Shiny应用程序另一部分的链接

作为常规应用程序迁移的一部分,运行初始RBAC迁移

找不到路径的一部分。从应用程序复制文件。WPF

仅需要登录Shiny应用程序的一部分

应用程序的哪一部分应该投入使用?

调试应用程序作为解决方案的一部分

如何在Azure上编写应用程序的一部分?

Scala错误处理-如果我的Scala代码的一部分失败,我想将function()作为程序的一部分执行

给每行的第一部分上色

列名第一部分的子集

隐藏第一部分