SwipeActions 在 tableView swift 5 xcode 13.4.1 中不起作用

Jos*_*var 2 xcode ios swift swift5

我正在对我的表格视图进行 TrailingSwipe 但它不起作用。不调用该函数trailingSwipeActionsConfigurationForRowAt

尝试使用leadingSwipeActionsConfigurationForRowAt,如果它对我有用,但对TrailingSwipe不起作用

有效的是我拥有表视图的委托和数据源

代码

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
        let delete = UIContextualAction(style: .normal, title: "delete2") {(action, view, completionHandler) in
            print("delete2 \(indexPath.row)")
        }
        let swipe = UISwipeActionsConfiguration(actions: [delete])
        return swipe
    }
Run Code Online (Sandbox Code Playgroud)

使用 Apple Mac M1 (MacBook Pro M1)

Ghu*_*bas 6

尝试一下,在 Xcode 13+、Apple Mac M1 和 Swift 5 上运行良好

 func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
} 
func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {}

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let delete = UIContextualAction(style: .destructive, title: "Delete") { (action, sourceView, completionHandler) in
      //  print("index path of delete: \(indexPath)")
        
        completionHandler(true)
    }
    let edit = UIContextualAction(style: .normal, title: "Edit") { [weak self] (action, sourceView, completionHandler)  in
        
        completionHandler(true)
    }
    delete.title = ""
    delete.image = UIImage(named: "deleteProfile")
    
    edit.title = ""
    edit.image = UIImage(named: "editProfile")
    
    let swipeAction = UISwipeActionsConfiguration(actions: [delete,edit])
    swipeAction.performsFirstActionWithFullSwipe = false // This is the line which disables full swipe
    return swipeAction
}
Run Code Online (Sandbox Code Playgroud)