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

我在UItableViewCell的前端设置了“添加到购物车”的操作。 我设置了背景颜色,图像和标题。 下面是我的代码。

@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支持文本图像 。 通过使用setImage:属性设置图像,基本上在创建对象时删除标题。 如果您同时需要文本和图像,则需要创建包含嵌入文本的图像

它是UIContextualAction中的错误。 除非表格视图单元格高度为91磅,否则它不会同时显示图像和标题 有关更多信息,请访问forums.apple

尝试这个

添加滑动以删除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 }