Created
January 30, 2021 21:53
-
-
Save uvolchyk/954b3e25a5e4562fc9f66289e6430846 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
import UIKit | |
let reuseIdentifier = "cellIdentifier" | |
class MagicController: UIViewController { | |
let data: [ViewData] = DataProvider.data | |
lazy var tableView: UITableView = { | |
let view = UITableView() | |
view.translatesAutoresizingMaskIntoConstraints = false | |
view.dataSource = self | |
view.register(MagicCell.self, forCellReuseIdentifier: reuseIdentifier) | |
view.tableFooterView = .init() | |
return view | |
}() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.addSubview(tableView) | |
NSLayoutConstraint.activate([ | |
tableView.leadingAnchor.constraint(equalTo: view.leadingAnchor), | |
tableView.topAnchor.constraint(equalTo: view.topAnchor), | |
tableView.trailingAnchor.constraint(equalTo: view.trailingAnchor), | |
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor) | |
]) | |
} | |
} | |
extension MagicController: UITableViewDataSource { | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
data.count | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
guard let cell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath) as? MagicCell | |
else { return UITableViewCell() } | |
cell.configureWithData(data[indexPath.row]) { (callback) in | |
tableView.performBatchUpdates { | |
callback() | |
} | |
} | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment