不在 UItableView 的滑动操作中显示标题 Swift 4

Not displaying the title in Swipe actions for UItableView Swift 4

我已经在 UItableViewCell 的前导侧为 "add to cart" 设置了一个动作。我已经设置了背景颜色、图像和标题。下面是我的代码。

 @available(iOS 11.0, *)
func tableView(_ tableView: UITableView, leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {

    let addToCart = UIContextualAction(style: .normal, title: "Add to Cart") { (action, view, nil) in
        print("Added to cart")

    }
    addToCart.title = "Add to Cart"
    addToCart.backgroundColor = #colorLiteral(red: 0.2196078449, green: 0.007843137719, blue: 0.8549019694, alpha: 1)
    addToCart.image = UIImage(named: "cart")

    return UISwipeActionsConfiguration(actions: [addToCart])
}

以前的尝试:我没有使用 addToCart.title = "Add to Cart" 定义标题,但是在没有得到它之后,我已经设置了它。

我添加的图片尺寸为25*25,背景清晰,.png格式。

UIContextualAction supports either text or image. By setting the image with setImage: property, basically remove the title when creating the object. If you want both text and image, you need to create images with embedded text.

这是 UIContextualAction. It does not show both image and title at the same time unless the table view cell height is 91 points. for more info you get forums.apple

中的错误

试试这个

Add swipe to delete UITableViewCell

@available(iOS 11.0, *)    
func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
            let action =  UIContextualAction(style: .normal, title: "", handler: { (action,view,completionHandler ) in
                //do stuff
                completionHandler(true)
                let data:NSDictionary = self.conversations[indexPath.row] as! NSDictionary
                print(data)
                let alert:UIAlertController = UIAlertController(title: "", message: "are you sure want to delete ?", preferredStyle: .alert)

                alert.addAction(UIAlertAction(title: "CANCEL", style: UIAlertActionStyle.cancel, handler: { (action) in
                }))
                self.present(alert, animated: true, completion: nil)
            })
            action.image = UIImage(named: "")
            action.backgroundColor = UIColor(red: 0/255, green: 148/255, blue: 204/255, alpha: 1.0)
            let confrigation = UISwipeActionsConfiguration(actions: [action])

            return confrigation
        }