【问题标题】:Deleting a row in a table cause program to crash删除表中的一行会导致程序崩溃
【发布时间】:2014-04-09 03:49:04
【问题描述】:

将我的代码精简到最基本的部分,当我按下删除按钮时,应用程序崩溃了。有什么想法吗?

这里是删除代码。正如我所说,最基本的。

  - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{


     if (editingStyle == UITableViewCellEditingStyleDelete) {
                //remove the deleted object from your data source.
                //If your data source is an NSMutableArray, do this




   [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];


            }


    }   

【问题讨论】:

  • 什么是崩溃错误?您正在从表格视图中删除行,但并未从数据源中删除项目。
  • 从数据源中删除对象完成了这项工作。谢谢老哥!

标签: ios objective-c uitableview delete-row


【解决方案1】:

试试这个

- (void)tableView:(UITableView *)tableView commitEditingStyle: (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle==UITableViewCellEditingStyleDelete)
    { 
        [dataArray removeObjectAtIndex:indexPath.row];
    }

    [tableView reloadData];
}

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-22
    • 2011-12-08
    • 2012-06-16
    • 2015-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多