Created
November 21, 2016 15:14
-
-
Save thiagolioy/d9828f635f06c6a2dcc1fad4a3e2418a to your computer and use it in GitHub Desktop.
This file contains 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
final class CharactersDatasource: NSObject, ItemsTableViewDatasource { | |
var items:[Character] = [] | |
weak var tableView: UITableView? | |
weak var delegate: UITableViewDelegate? | |
required init(items: [Character], tableView: UITableView, delegate: UITableViewDelegate) { | |
self.items = items | |
self.tableView = tableView | |
self.delegate = delegate | |
super.init() | |
tableView.register(cellType: CharacterTableCell.self) | |
self.setupTableView() | |
} | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return self.items.count | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = tableView.dequeueReusableCell(for: indexPath, cellType: CharacterTableCell.self) | |
let character = self.items[indexPath.row] | |
cell.setup(item: character) | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment