如何在不重新加载数据的情况下更新tableview单元格?

iso*_*tsn 3 uitableview ios swift swift4

我有一个tableview单元格。在此单元格中,有一个视图可播放视频,并在该视频视图下显示星级。

我希望用户在观看视频的%50部分之前不要对其评分。如果用户观看了视频的%50部分,则可以为该视频评分。

在我的模型课中,我设置了一个计时器。当用户单击视频播放计时器时,计时器开始播放,如果计时器==视频持续时间/ 2,则用户可以评分。除此以外

用户显示警报消息。

我所做的事情: 当计时器==视频时长/ 2时,我重新加载了tableview /或只是重新加载了该行

但视频已停止。

我怎样才能做到这一点 ?有什么建议或示例代码吗?

这是我的播放按钮自定义委托函数

if(vlist[index.row].timerIndex >= 10){
                        print("====================!!!!!!!!!!^^^^^^^^^^^^^^======RATABLEEEEEEEEEEE")
                        vlist[index.row].isRatable = true
                        self.rateUserTableView.reloadRows(at: [index], with: .none)
                        MediaManager.sharedInstance.player?.embeddedContentView = cell.videoPlayerView
                        vlist[index.row].timer?.invalidate()
                    }
Run Code Online (Sandbox Code Playgroud)

这是我的tableview ccellForRowAt

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        guard let vlist = videoList ,!vlist.isEmpty else {let cell = UITableViewCell()
            cell.selectionStyle = .none
            cell.backgroundColor = .clear
            cell.textLabel?.textAlignment = .center
            cell.textLabel?.textColor = UIColor.black
            cell.textLabel?.text = "nodataavaiable".localized()
            return cell
        }
        let cell = tableView.dequeueReusableCell(withIdentifier: "RateUserCell", for: indexPath) as! RateUserCell
        //---
        let playing = vlist[indexPath.row].isPlaying
        cell.delegate = self
        cell.indexPath = indexPath
        cell.playButton.isHidden = playing
        cell.titleView.isHidden = playing
        //---
        if(indexPath.row % 2 == 0) {
            cell.thumbnailImageView.image = UIImage(named:"thumb1")
        }
        else {
            cell.thumbnailImageView.image = UIImage(named:"thumb2")
        }
        cell.titleLabel.text = vlist[indexPath.row].shortDesc
        cell.userName.text = vlist[indexPath.row].person
        cell.userCount.text = String(vlist[indexPath.row].voteCount!)
        cell.voteCount.text = String(vlist[indexPath.row].sumScore!)
        cell.cosmos.rating = Double(vlist[indexPath.row].userVote!)



        if(self.statusId == 3 ){
            if(vlist[indexPath.row].userVote! > 0){
                cell.cosmos.didFinishTouchingCosmos =  { rating in
                    self.setVote(videoId: vlist[indexPath.row].videoId!, vote: Int(rating))
                }
            }
            else {

                if(vlist[indexPath.row].isRatable == true){
                    cell.cosmos.didTouchCosmos = { rating in
                        cell.cosmos.settings.updateOnTouch = true
                        cell.cosmos.rating = rating
                        self.setVote(videoId: vlist[indexPath.row].videoId!, vote: Int(rating))
                    }
                }
                else {
                    cell.cosmos.didTouchCosmos = { rating in
                        cell.cosmos.rating = Double(0.0)
                        self.showAlertMessage(vc: self, titleStr: "error".localized(), messageStr: "rateTimeMsj".localized(), img: "ntf-5", buttonColor: UIColor.red)
                        cell.cosmos.settings.updateOnTouch = false
                    }

                }

            }

        }
        else if(self.statusId == 4){
            cell.cosmos.isHidden = true
        }
        return cell
    }
Run Code Online (Sandbox Code Playgroud)

Mil*_*sáľ 6

Try using tableView.cellForRow to get the cell and configure it directly yourself only with the modified data:

// this should give you currently visible cell for indexPath
if let ratableCell = tableView.cellForRow(at: indexPath) as? RatableCell {
    // instead of telling tableView to reload this cell, just configure here
    // the changed data, e.g.:
    ratableCell.configureRate(10)
}
Run Code Online (Sandbox Code Playgroud)