我正在使用Swift 4创建一个iOS应用程序而我没有使用Storyboard.要从Table View Controller中删除行,用户会向左滑动该行,然后单击"删除"按钮.
这是我用来实现的代码(没有使用外部库):
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
self.isAccessibilityElement = true
self.accessibilityLabel = "Delete row"
let deleteAction = UIContextualAction(style: .normal , title: "DELETE") { (action, view, handler) in
self.removeRowFromMyList(indexPath: indexPath.row)
MyListController.stations.remove(at: indexPath.row)
self.tableView.deleteRows(at: [indexPath], with: .automatic)
self.tableView.setEditing(false, animated: true)
self.tableView.reloadData()
}
let swipeAction = UISwipeActionsConfiguration(actions: [deleteAction])
swipeAction.performsFirstActionWithFullSwipe = false
return swipeAction
}
Run Code Online (Sandbox Code Playgroud)
我确实检查了其他问题,但没有一个问题可以解决.如有任何其他解决此问题需要了解的信息,请随时在此处发表评论.谢谢 :)