Created
July 5, 2016 05:49
-
-
Save macbaszii/0d1efcd36948e17153880af1923c5036 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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