UITableViewCell内容消失

时间:2018-11-14 18:39:36

标签: ios swift uitableview uiactionsheet uicontextualaction

我有一个uiTableView,其中有3个单元格,这些单元格是通过uiContextualAction委托方法实现的trailingSwipeActionsConfigurationForRowAt

点击uiContextualAction时,我将显示一个actionSheet,其中包含两项操作-删除和关闭。

在未按任何操作的情况下显示actionSheet时,所有3个单元格(特别是uiImageView)的单元格内容突然消失。

uiTableViews是否存在导致此问题的固有原因?我在上述流程中都设置了断点,但没有采取补救措施。任何想法都将不胜感激。

  

在展示actionSheet之前-UITableViewCell的ImageView(带有蓝色渐变图像的红色背景)

BEFORE presented actionSheet - ImageView (red background w/ blue gradient image) of UITableViewCell

  

在呈现的actionSheet之后-ImageView(红色背景,没有蓝色渐变图像)

AFTER on presented actionSheet - ImageView (red background w/o blue gradient image)

    func tableView(_ tableView: UITableView, trailingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration? {
    let delete = UIContextualAction(style: .normal, title: "") { (action, view, completion) in
        self.onDeleteCell(indexPath)
        completion(true)
    }

    delete.backgroundColor = UIColor.red
    delete.image = #imageLiteral(resourceName: "x_circle")

    let config = UISwipeActionsConfiguration(actions: [delete])

    config.performsFirstActionWithFullSwipe = false

    return config
}

func onDelete(_ indexPath: IndexPath) {
     AlertController.showActionSheet(self, title: nil, message: nil, actionOneTitle: "Delete", actionOneStyle: .destructive, actionTwoTitle: "Dismiss", actionTwoStyle: .cancel) { (_) in                    
          self.updateCells(indexPath)              
     }
}


    //From custom AlertController class
    static func showActionSheet(_ inViewController: UIViewController, title: String?, message: String?, actionOneTitle: String, actionOneStyle: UIAlertAction.Style, actionTwoTitle: String, actionTwoStyle: UIAlertAction.Style, actionOneHandler: @escaping ((UIAlertAction) -> Void)) {

    let alert = UIAlertController(title: title, message: message, preferredStyle: .actionSheet)
    let actionOne = UIAlertAction(title: actionOneTitle, style: actionOneStyle, handler: actionOneHandler)
    alert.addAction(actionOne)

    let actionTwo = UIAlertAction(title: actionTwoTitle, style: actionTwoStyle, handler: nil)
    alert.addAction(actionTwo)

    inViewController.present(alert, animated: true, completion: nil)
}

1 个答案:

答案 0 :(得分:0)

仍然不确定问题是什么/是...但是我将矢量图像替换为png,它似乎可以渲染并且不再突然消失了。.

这不是一个确定的解决方案,但现在它对我来说确实有效。