1부터 50까지의 숫자 출력하기
import UIKit
final class TableViewNumbers: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let tableView = UITableView(frame: view.frame)
tableView.dataSource = self
view.addSubview(tableView)
}
}
extension TableViewNumbers: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 50
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell
if let reusableCell = tableView.dequeueReusableCell(withIdentifier: "CellId") {
cell = reusableCell
} else {
cell = UITableViewCell(style: .default, reuseIdentifier: "CellId")
}
cell.textLabel?.text = "\((indexPath.row)+1)"
return cell
}
}

