SwiftyJD
SwiftyJD

Reputation: 5441

How to show an activity Indicator inside a tableViewCell while its loading?

I currently have a tableView, one of the cells contains a webView. When the webView is loading I would like it to show an activity indicator but only in that cell. Currently the indicator shows but doesn't animate and when the video appears it doesn't hide and stays on top of the video. Here is the code for the 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")

  }
}

Here is the 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

Upvotes: 0

Views: 660

Answers (1)

matt
matt

Reputation: 535306

The problem is that the cell is not the web view's delegate, so your web view delegate methods in the cell are never being called.

Upvotes: 1

Related Questions