如何在tableViewCell加载时显示一个活动指标?

时间:2016-04-14 01:44:33

标签: swift uitableview uiwebview uiactivityindicatorview

我目前有一个tableView,其中一个单元格包含一个webView。当webView加载时,我希望它显示活动指示符,但仅在该单元格中显示。目前,指标显示但没有动画,当视频显示时,它不会隐藏并保持在视频之上。这是tableViewCell的代码:

class VideoOnDetailCell: UITableViewCell {
      @IBOutlet weak var videoDetail: UIWebView!
      @IBOutlet weak var activityIndicator: UIActivityIndicatorView!

  func webViewDidStartLoad(webView: UIWebView) {
    activityIndicator.hidden = false
    activityIndicator.startAnimating()
    NSLog("The web view is starting to load")
  }
  func webViewDidFinishLoad(webView: UIWebView){
    activityIndicator.hidden = true
    activityIndicator.stopAnimating()
    NSLog ("The web view has finished loading")

  }
}

这是cellForRowAtIndexPath:

  let cell = tableView.dequeueReusableCellWithIdentifier("videoDetail", forIndexPath: indexPath) as!
      VideoOnDetailCell

      cell.videoDetail.allowsInlineMediaPlayback = true
      cell.videoDetail.loadHTMLString("<iframe width=\"\(cell.videoDetail.frame.width)\" height=\"\(200)\" src=\"\(videoURL[indexPath.row])/?&playsinline=1\" frameborder=\"0\" allowfullscreen></iframe>", baseURL: nil)
      self.DetailTvTableView.rowHeight = 200
      return cell

1 个答案:

答案 0 :(得分:1)

问题是该单元格不是Web视图的委托,因此永远不会调用单元格中的Web视图委托方法。