我正在使用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)
我确实检查了其他问题,但没有一个问题可以解决.如有任何其他解决此问题需要了解的信息,请随时在此处发表评论.谢谢 :)
使用Apple 的UIAccessibility中的辅助功能自定义操作
您只需要设置辅助功能自定义操作:
cell.accessibilityCustomActions = [UIAccessibilityCustomAction(name: "Delete", target: self, selector: #selector(theCustomAction))]
@objc private func theCustomAction() -> Bool {
//Do anything you want here
return true
}
Run Code Online (Sandbox Code Playgroud)
更新:
所以我确实重新创建了该项目,但这次我使用的是 Storyboards(我不是最后一次),我从 Cocoapods 导入了SwipeCellKit 库,我遵循了他们的文档,VoiceOver 工作得非常好,从其中删除了一个单元格 indexPath.row没有问题。
| 归档时间: |
|
| 查看次数: |
1409 次 |
| 最近记录: |