Skip to content

Instantly share code, notes, and snippets.

@IhwanID
Created September 6, 2020 08:04
Show Gist options
  • Save IhwanID/7d36029b95f54ff34088f729daba5f70 to your computer and use it in GitHub Desktop.
Save IhwanID/7d36029b95f54ff34088f729daba5f70 to your computer and use it in GitHub Desktop.
Simpe Table View
//
// 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