【发布时间】:2018-07-31 19:12:28
【问题描述】:
我有一个表格视图单元格。 在此单元格中,有一个播放视频的视图,以及此下方的星级评分 视频观看。
我希望用户在观看视频的 %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()
}
这是我的表格视图 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
}
【问题讨论】:
-
不相关,但为什么
videoList是可选的,为什么每次调用cellForRow时都要检查空数组(这种情况经常发生)。这是不必要的昂贵。数据源数组应该是非可选的,如果numberOfRows返回 0,则根本不会调用cellForRow。从数组 (vlist[indexPath.row]) 中获取相同的对象 6 或 7 次是不必要的昂贵,也是。 -
为什么需要重新加载表格或单元格??
-
因为在阅读了您的问题后,我明白您希望视频继续播放。
标签: ios swift uitableview swift4