Skip to content

Instantly share code, notes, and snippets.

@sigidhanafi
Last active November 12, 2020 23:06
Show Gist options
  • Save sigidhanafi/3fdb2fdc9b21b0b649c43ebae49a17df to your computer and use it in GitHub Desktop.
Save sigidhanafi/3fdb2fdc9b21b0b649c43ebae49a17df to your computer and use it in GitHub Desktop.
Getting tsarted with UITableView
//
// ViewController.swift
// GettingStartedUITableView
//
// Created by Sigit on 13/11/20.
//
import UIKit
class ViewController: UIViewController {
// create property tableview
private let tableView: UITableView = {
let tableView = UITableView()
tableView.backgroundColor = .white
tableView.translatesAutoresizingMaskIntoConstraints = false
return tableView
}()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
view.backgroundColor = .white
// call function to setup view / tableview (4)
self.setupView()
}
// create function to setup our tableview (1)
private func setupView() {
// add tableview to VC view (2)
view.addSubview(tableView)
// setting up constrains (3)
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true
tableView.rightAnchor.constraint(equalTo: view.rightAnchor).isActive = true
tableView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true
tableView.leftAnchor.constraint(equalTo: view.leftAnchor).isActive = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment