Skip to content

Instantly share code, notes, and snippets.

@macbaszii
Created July 5, 2016 05:49
Show Gist options
  • Save macbaszii/0d1efcd36948e17153880af1923c5036 to your computer and use it in GitHub Desktop.
Save macbaszii/0d1efcd36948e17153880af1923c5036 to your computer and use it in GitHub Desktop.
private let CellDefaultHeight: CGFloat = 80.0
private let PlaceholderCellIdentifier = "PlaceholderCell"
private let ProfileCellIdentifier = "ProfileCell"
// MARK: - UITableView Protocol Conformance
extension ViewController: UITableViewDataSource {
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if viewModel.shouldShowPlaceholder {
return Int(CGRectGetHeight(tableView.bounds) / CellDefaultHeight)
} else {
return viewModel.numberOfRows()
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if viewModel.shouldShowPlaceholder {
let cell = tableView.dequeueReusableCellWithIdentifier(PlaceholderCellIdentifier, forIndexPath: indexPath) as! PlaceholderCell
return cell
} else {
let cell = tableView.dequeueReusableCellWithIdentifier(ProfileCellIdentifier, forIndexPath: indexPath) as! ProfileCell
let cellViewModel = CellViewModel(profile: viewModel.profile(at: indexPath))
cell.configureCell(with: cellViewModel)
return cell
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment