代码之家  ›  专栏  ›  技术社区  ›  Chris

UITableViewCell内容将消失

  •  -1
  • Chris  · 技术社区  · 7 年前

    我有一个 uiTableView 有3个单元格有一个 uiContextualAction 通过 trailingSwipeActionsConfigurationForRowAt 委托方法。

    语境作用 我显示一个 actionSheet 有两个操作-删除和取消。

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

    有什么内在的东西吗 uiTableViews

    在提交操作表之前-UITableViewCell的ImageView(红色背景和蓝色渐变图像)

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

    在提交操作表后-图像视图(红色背景,无蓝色渐变图像)

    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 回复  |  直到 7 年前
        1
  •  0
  •   Chris    7 年前

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

    推荐文章