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
  • Select an option

  • Save abhishekbedi1432/d74402cfd5978c934b71ef85c4966cee to your computer and use it in GitHub Desktop.

Select an option

Save abhishekbedi1432/d74402cfd5978c934b71ef85c4966cee to your computer and use it in GitHub Desktop.

Revisions

  1. abhishekbedi1432 revised this gist Jul 22, 2017. 1 changed file with 25 additions and 20 deletions.
    45 changes: 25 additions & 20 deletions UITableView.swift
    Original file line number Diff line number Diff line change
    @@ -1,32 +1,37 @@
    // Playground - noun: a place where people can play

    import UIKit
    import XCPlayground

    class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource
    {
    class ViewController: UIViewController {
    var tableView: UITableView!
    var items: NSMutableArray!
    var items = ["Apple","Mango","Grapes"]

    override func viewDidLoad() {
    super.viewDidLoad()
    self.items = NSMutableArray(array: ["Hello 1","Hello 2","Hello 3"])
    self.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480)
    self.tableView = UITableView(frame:self.view!.frame)
    self.tableView!.delegate = self
    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!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    self.view?.addSubview(self.tableView)


    self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    self.view.addSubview(self.tableView)
    }
    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int{
    return self.items.count;
    }


    extension ViewController: UITableViewDataSource {

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return self.items.count
    }
    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!{
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
    cell.textLabel.text = "\(self.items[indexPath.row])"
    return cell

    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()
    // ctrl.viewDidLoad() //Not needed
    ctrl.view
    XCPShowView(identifier: "Playground VC", view: ctrl.view)
  2. @watert watert revised this gist Jun 9, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion UITableView.swift
    Original file line number Diff line number Diff line change
    @@ -28,5 +28,5 @@ class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSour
    }

    var ctrl = ViewController()
    ctrl.viewDidLoad()
    // ctrl.viewDidLoad() //Not needed
    ctrl.view
  3. @watert watert renamed this gist Jun 9, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. @watert watert renamed this gist Jun 9, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. @watert watert created this gist Jun 9, 2014.
    32 changes: 32 additions & 0 deletions UITableView.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    // Playground - noun: a place where people can play

    import UIKit

    class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource
    {
    var tableView: UITableView!
    var items: NSMutableArray!
    override func viewDidLoad() {
    super.viewDidLoad()
    self.items = NSMutableArray(array: ["Hello 1","Hello 2","Hello 3"])
    self.view.frame = CGRect(x: 0, y: 0, width: 320, height: 480)
    self.tableView = UITableView(frame:self.view!.frame)
    self.tableView!.delegate = self
    self.tableView!.dataSource = self
    self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
    self.view?.addSubview(self.tableView)

    }
    func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int{
    return self.items.count;
    }
    func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!{
    let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
    cell.textLabel.text = "\(self.items[indexPath.row])"
    return cell
    }
    }

    var ctrl = ViewController()
    ctrl.viewDidLoad()
    ctrl.view