首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UITableView.setEditing()无法禁用编辑模式

UITableView.setEditing()无法禁用编辑模式
EN

Stack Overflow用户
提问于 2018-02-12 02:55:29
回答 1查看 954关注 0票数 0

我很难让我的UITableView退出编辑模式。下面是我如何进入和退出编辑模式,请参阅下面的链接以获得源代码-

进入编辑模式

DbgTableViewHandler.swift(126):

代码语言:javascript
复制
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        ...
        table.setEditing(true, animated: true);
        ...
    }

离开编辑模式

DbgTableView.swift(105):

代码语言:javascript
复制
    func removeCell(_ index : Int) {
        ...
        setEditing(false, animated: true);
        ...
    }

问题

  • 如何使示例中的表退出编辑模式?
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-12 04:21:47

删除单元格的方式是错误的,您应该使用deleteRows方式删除它,而不是从dataSource中删除,然后重新加载表,用下面的代码替换它,它就能工作了。

代码语言:javascript
复制
func removeCell(_ index : Int) {
    beginUpdates()
    myDbgCells.remove(at: index);
    let i = IndexPath(row: index, section: 0)
    deleteRows(at: [i], with: .automatic)
    endUpdates()

    //turn mode off (just cause, for demo's sake)
    setEditing(false, animated: true);

    print("DbgTableView.removeCell():       cell removed");

    return;
}

此外,对于这样一个简单的屏幕,项目过于复杂,请记住更多的代码=更难调试

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48738937

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档