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
}

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...