UITableVIewCell,滑动时显示编辑联系人按钮



在UITableViewCell上滑动时,如何显示编辑联系人按钮?事件从未引发,编辑按钮也从未出现。

对于Swift 4&iOS 11+

func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
// since the style is destructive, so it will have a red background by default.
// change it to .normal and it will have a blue background by default..
let editAction = UIContextualAction(style: .destructive, title: "Edit Contact") { _, _, complete in
// continue your logic..
// write your code to move to next screen.. Perform segue or move using storyboards..
complete(true)
}
// if you want to add icon, then you can do it this way..
editAction.image = UIImage(named: "editContact")
// you can set your own background color for the button like this..
editAction.backgroundColor = .orange
let configuration = UISwipeActionsConfiguration(actions: [editAction])
//set to false to prevent a full swipe from performing the first action..
configuration.performsFirstActionWithFullSwipe = true
return configuration
}

最新更新