Created
September 6, 2020 08:04
-
-
Save IhwanID/7d36029b95f54ff34088f729daba5f70 to your computer and use it in GitHub Desktop.
Simpe Table View
This file contains hidden or 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
// | |
// ViewController.swift | |
// simple-table-view | |
// | |
// Created by Ihwan ID on 06/09/20. | |
// Copyright © 2020 Ihwan ID. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
private let tableView: UITableView = { | |
let tableView = UITableView() | |
return tableView | |
}() | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
view.addSubview(tableView) | |
tableView.dataSource = self | |
tableView.delegate = self | |
} | |
override func viewDidLayoutSubviews() { | |
super.viewDidLayoutSubviews() | |
tableView.frame = view.bounds | |
} | |
} | |
extension ViewController: UITableViewDataSource, UITableViewDelegate{ | |
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return 15 | |
} | |
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | |
let cell = UITableViewCell() | |
cell.textLabel?.text = "Cell at \(indexPath.row+1)" | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment