01-ViewController-5.swift 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import UIKit
  2. import Kingfisher
  3. class ViewController: UIViewController {
  4. lazy var tableView: UITableView = {
  5. let tableView = UITableView(frame: .zero)
  6. tableView.register(SampleCell.self, forCellReuseIdentifier: "SampleCell")
  7. tableView.translatesAutoresizingMaskIntoConstraints = false
  8. tableView.rowHeight = 80
  9. return tableView
  10. }()
  11. override func viewDidLoad() {
  12. super.viewDidLoad()
  13. // Do any additional setup after loading the view.
  14. print(KingfisherManager.shared)
  15. tableView.dataSource = self
  16. view.addSubview(tableView)
  17. NSLayoutConstraint.activate([
  18. tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor),
  19. tableView.leadingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.leadingAnchor),
  20. tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
  21. tableView.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor)
  22. ])
  23. }
  24. }
  25. extension ViewController: UITableViewDataSource {
  26. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  27. 1
  28. }
  29. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  30. let cell = tableView.dequeueReusableCell(withIdentifier: "SampleCell", for: indexPath) as! SampleCell
  31. cell.sampleLabel.text = "Index \(indexPath.row)"
  32. cell.sampleImageView.backgroundColor = .lightGray
  33. return cell
  34. }
  35. }