Skip to content

Instantly share code, notes, and snippets.

@mhijack
Created April 21, 2021 22:54
Show Gist options
  • Save mhijack/59d3b052fdef1f6acc60f384da96f895 to your computer and use it in GitHub Desktop.
Save mhijack/59d3b052fdef1f6acc60f384da96f895 to your computer and use it in GitHub Desktop.
class EmptyTableViewDataSource: NSObject, UITableViewDataSource {
let identifier: String
let emptyModel: EmptyTableViewCellModel
let cellConfigurator: EmptyTableViewCellConfigurator
init(identifier: String = "empty-table-view-cell",
emptyModel: EmptyTableViewCellModel = EmptyTableViewCellModel(),
cellConfigurator: EmptyTableViewCellConfigurator = PlainEmptyTableViewCellConfigurator()) {
self.identifier = identifier
self.emptyModel = emptyModel
self.cellConfigurator = cellConfigurator
super.init()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as? EmptyTableViewCell else { return EmptyTableViewCell() }
cellConfigurator.configure(cell: cell, forDisplaying: emptyModel)
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment