微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。