ios - 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
}
推荐阅读
- reactjs - CSRF 令牌不匹配 - 使用 React 0.13
- java - 迭代器 hasNext 用于获取最后一条记录
- swift - Xcode 说应用程序正在运行,但在我的 iOS 14 设备上找不到应用程序
- python - 如何比较子列表python中的元素?
- python - django-import-export 将列附加到导入的 .xlsx
- regex - 正则表达式检测重复
- python-3.x - 菜鸟可怕地卡在最有可能是一个简单的问题上
- checkbox - 当值相同的vuejs时,多个复选框不起作用
- html - 表格未正确对齐
- mysql-workbench - MySQL Workbench 的数据有限制吗?