Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. import UIKit
  2.  
  3. class ViewController: UIViewController {
  4.  
  5. @IBOutlet weak var tableView: UITableView!
  6.  
  7. override func viewDidLoad() {
  8. super.viewDidLoad()
  9. tableView.dataSource = self
  10. }
  11.  
  12. }
  13.  
  14. extension ViewController: UITableViewDataSource {
  15. ///總共有幾個Row
  16. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  17. return 10
  18. }
  19.  
  20. ///每個Row所顯示的Cell
  21. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  22. ///透過Identifier來取得Cell
  23. guard let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell") else {
  24. fatalError()
  25. }
  26.  
  27. cell.textLabel?.text = "\(indexPath.row)"
  28. return cell
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement