Skip to content

Instantly share code, notes, and snippets.

@mhijack
Last active April 23, 2021 17:10
Show Gist options
  • Save mhijack/02f88ecfa75e420e47284ad3c36dc614 to your computer and use it in GitHub Desktop.
Save mhijack/02f88ecfa75e420e47284ad3c36dc614 to your computer and use it in GitHub Desktop.
struct EmptyTableViewCellModel {
var icon: UIImage
var descriptionText: String
var secondaryText: String
var actionText: String
var action: (() -> ())?
init(icon: UIImage = UIImage(named: "default-empty-image")!,
descriptionText: String = NSLocalizedString("empty-cell-description", value: "It's kinda lonely out there", comment: "Empty table view cell description text"),
secondaryText: String = "",
actionText: String = "",
action: (() -> ())? = nil) {
self.icon = icon
self.descriptionText = descriptionText
self.secondaryText = secondaryText
self.actionText = actionText
self.action = action
}
}
protocol EmptyTableViewCellConfigurator {
func configure(cell: EmptyTableViewCell, forDisplaying emptyModel: EmptyTableViewCellModel)
}
class PlainEmptyTableViewCellConfigurator: EmptyTableViewCellConfigurator {
func configure(cell: EmptyTableViewCell, forDisplaying emptyModel: EmptyTableViewCellModel) {
guard let cell = cell as? PlainEmptyTableViewCell else { return }
cell.selectionStyle = .none
cell.icon = emptyModel.icon
cell.descriptionText = emptyModel.descriptionText
if emptyModel.actionText.isEmpty {
cell.actionButton.isHidden = true
} else {
cell.actionText = emptyModel.actionText
}
cell.iconImageView.image = emptyModel.icon
cell.descriptionLabel.text = emptyModel.descriptionText
cell.actionButton.setTitle(emptyModel.actionText, for: .normal)
cell.action = emptyModel.action
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment