Skip to content

Instantly share code, notes, and snippets.

@mhijack
Created April 20, 2021 19:42
Show Gist options
  • Save mhijack/da2cae7d304bef7e4c9c0719d7c6ae60 to your computer and use it in GitHub Desktop.
Save mhijack/da2cae7d304bef7e4c9c0719d7c6ae60 to your computer and use it in GitHub Desktop.
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch data.count == 0 {
case true:
return 1
case false:
return data.count
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch data.count == 0 {
case true:
/// No content
guard let cell = tableView.dequeueReusableCell(withIdentifier: "empty-cell-id", for: indexPath) as? EmptyTableViewCell
else { return EmptyTableViewCell() }
let noResultsView = NoResultsView()
noResultsView.setContent()
cell.setup(view: noResultsView)
return cell
case false:
/// User cell
guard let cell = tableView.dequeueReusableCell(withIdentifier: "cell-id", for: indexPath) as? DataTableViewCell
else { return DataTableViewCell() }
cell.setContent(data: data[indexPath.row])
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment