我在tableView中使用TrailingSwipeActionsConfigurationForRowAt,偶尔注意到在向左滑动行以显示操作时,偶尔会出现抖动或断断续续的响应。绝对不流畅。有时,所揭示的动作甚至消失并再次出现。我相信我的函数定义很标准:
override func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
let modelObject = self.fetchedResultsController.object(at: indexPath)
let deleteAction = UIContextualAction(style: UIContextualAction.Style.normal, title: "Delete") { (action: UIContextualAction, sourceView: UIView, completionHandler: (Bool) -> Void) in
// set completion to remove displayed actions
completionHandler(true)
// delete object here
}
let editAction = UIContextualAction(style: UIContextualAction.Style.normal, title: "Edit") { (action: UIContextualAction, sourceView: UIView, completionHandler: (Bool) -> Void) in
// set completion to remove displayed actions
completionHandler(true)
// edit object here
}
deleteAction.backgroundColor = UIColor.red
editAction.backgroundColor = UIColor.gray
var actions = [UIContextualAction]()
actions = [deleteAction, editAction]
let swipeActions = UISwipeActionsConfiguration(actions: actions)
swipeActions.performsFirstActionWithFullSwipe = false
return swipeActions
}