【问题标题】:UITableVIewCell , show edit contact button on swipeUITableVIewCell ,在滑动时显示编辑联系人按钮
【发布时间】:2021-01-31 15:02:01
【问题描述】:

如何在 UITableViewCell 上滑动时显示编辑联系人按钮?永远不会引发该事件,并且永远不会出现编辑按钮。

【问题讨论】:

    标签: ios uitableview cocoa-touch uikit


    【解决方案1】:

    适用于 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
    }
    

    【讨论】:

    • 另外,我想为编辑联系人 VC 添加 NavigationVC,并希望将其与 TableViewCell @naveedulhassan5 中的 EditContact 滑动按钮链接起来
    • 我想使用滑动编辑联系人按钮从联系人屏幕导航到编辑联系人屏幕,这就是我想要的
    • //我正在尝试根据单击的 tableView 单元格呈现一个 viewController。 //目前如果他们都被点击了,他们会重定向到同一个viewController,我将如何改变这个?扩展 SettingsVC: TableViewNew { func onClickCell(index: Int) { let aboutusVC = AboutUsVC() self.navigationController?.pushViewController(aboutusVC, animated: true) let tncVc = TermsAndConditionsVC() self.navigationController?.pushViewController(tncVc, animated: true ) } }
    猜你喜欢
    • 2011-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    相关资源
    最近更新 更多