Skip to content

Instantly share code, notes, and snippets.

@abhishekbedi1432
Forked from watert/UITableView.swift
Last active July 22, 2017 07:38
Show Gist options
  • Save abhishekbedi1432/d74402cfd5978c934b71ef85c4966cee to your computer and use it in GitHub Desktop.
Save abhishekbedi1432/d74402cfd5978c934b71ef85c4966cee to your computer and use it in GitHub Desktop.
UITableView example in iOS Playground in Swift 3
import UIKit
import XCPlayground
class ViewController: UIViewController {
var tableView: UITableView!
var items = ["Apple","Mango","Grapes"]
override func viewDidLoad() {
super.viewDidLoad()
self.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480)
self.tableView = UITableView(frame:self.view.frame)
self.tableView!.dataSource = self
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
self.view.addSubview(self.tableView)
}
}
extension ViewController: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.items.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as UITableViewCell
let item = items[indexPath.row]
cell.textLabel?.text = item
return cell
}
}
var ctrl = ViewController()
XCPShowView(identifier: "Playground VC", view: ctrl.view)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment