tableview cell 左划删除功能

shiguowen 2018-02-23 07:22:26

现在左划可以滑倒最左边,就删除了数据,这么做可以不允许滑倒最左边

用的是这个方法的默认实现
tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath)
...全文
1168 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
virtualxmars 2018-03-10
  • 打赏
  • 举报
回复
请阅读这个文档 https://developer.apple.com/documentation/uikit/uiswipeactionsconfiguration 通过tableViewDelegate的tableView(_:trailingSwipeActionsConfigurationForRowAt:)回调方法可以返回一个UISwipeActionsConfiguration对象,而该对象可以指定: var performsFirstActionWithFullSwipe: Bool A Boolean value indicating whether a full swipe automatically performs the first action. 来支持“划到边缘自动执行‘的行为
shiguowen 2018-02-24
  • 打赏
  • 举报
回复
引用 1 楼 disburden 的回复:
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
        return "删除"
    }
实现这两个协议方法应该就不会了,我就是这么用的
向左拖会出现 return “删除--” 返回的字符串,点击会删除,但还是可以直接拖到最左边,我这里需要不让它可以拖到最左边,怎么弄?
不担心 2018-02-23
  • 打赏
  • 举报
回复
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    
    func tableView(_ tableView: UITableView, titleForDeleteConfirmationButtonForRowAt indexPath: IndexPath) -> String? {
        return "删除"
    }
实现这两个协议方法应该就不会了,我就是这么用的

29,027

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧