You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

iOS13下UITableView侧滑代理方法trailingSwipeActionsConfigurationForRowAt未调用

iOS 13.7中tableView(_:trailingSwipeActionsConfigurationForRowAt:)不触发的解决方案

问题根源

iOS 13及更早版本中,系统要求必须同时实现旧版的编辑提交方法,才会触发trailingSwipeActionsConfigurationForRowAt:。而iOS 14+对这一逻辑做了优化,无需依赖旧方法也能正常调用新的侧滑配置接口。

解决方案

  1. 添加旧版编辑提交方法
    在你的tableView代理中补充实现tableView(_:commit:forRowAt:)方法:
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
    if editingStyle == .delete {
        presenter.requestDeletion(at: indexPath.row)
        // 若需手动更新列表UI,可添加该行代码
        // tableView.deleteRows(at: [indexPath], with: .automatic)
    }
}
  1. 检查tableView编辑状态
    确认你的tableView没有被强制设置为不可编辑:
// 确保没有这类禁用编辑的代码,或根据业务需求调整
// tableView.isEditing = false

如果是通过Storyboard/XIB创建的tableView,检查属性面板中的「Editing」选项是否未被禁用。

  1. 验证代理关联
    再次确认你的ViewController已正确设置为tableView的delegate:
override func viewDidLoad() {
    super.viewDidLoad()
    tableView.delegate = self
    tableView.dataSource = self
}

完成以上步骤后,iOS 13.7模拟器中侧滑操作应该能正常触发断点并显示删除按钮。

内容的提问来源于stack exchange,提问作者corscheg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.07 19:55:30