Skip to content

Instantly share code, notes, and snippets.

@foobra
Last active August 10, 2017 05:22
Show Gist options
  • Save foobra/f0a8cc1fcd3ef2081e1b6eb6cbc70e25 to your computer and use it in GitHub Desktop.
Save foobra/f0a8cc1fcd3ef2081e1b6eb6cbc70e25 to your computer and use it in GitHub Desktop.
extension HomePageTimelineVC: UITableViewDataSource, UITableViewDelegate {
public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch viewModel.vms[indexPath.row] {
case let model as TimelineCellPhotoViewModel:
let cell = tableView.dequeueReusableCell(withIdentifier: TimelineCellPhoto.className) as? TimelineCellPhoto
?? TimelineCellPhoto(.timeline, style: .default, reuseIdentifier: TimelineCellPhoto.className)
cell.configCell(viewModel: model, vc: self)
return cell
case let model as TimelineCellVideoViewModel:
let cell = tableView.dequeueReusableCell(withIdentifier: TimelineVideoCell.className) as? TimelineVideoCell
?? TimelineVideoCell(.timeline, style: .default, reuseIdentifier: TimelineVideoCell.className)
cell.configCell(viewModel: model, vc: self)
return cell
default:
fatalError()
}
}
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return viewModel.vms.count
}
public func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {
if let model = viewModel.vms[indexPath.row] as? TimelineCellVideoViewModel {
model.state.playerPauseProxy?()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment