Created
September 21, 2015 16:05
-
-
Save agnosticdev/c88b573b544beb3a9b47 to your computer and use it in GitHub Desktop.
Implementation of a UITableView in a ViewController in Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class MyViewController: UIViewController,UITableViewDelegate,UITableViewDataSource { | |
var tableData: [String] = ["Table Item One", "Table Item Two"] | |
var tableViewLocal: UITableView! | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
self.tableViewLocal = UITableView(); | |
self.tableViewLocal.frame = CGRectMake(0, 0, 320, 500); | |
self.tableViewLocal.delegate = self | |
self.tableViewLocal.dataSource = self; | |
//self.tableViewLocal.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") | |
self.view.addSubview(tableViewLocal) | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
func numberOfSectionsInTableView(tableView: UITableView) -> Int { | |
return 1 | |
} | |
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | |
return self.tableData.count; | |
} | |
func tableView(tableView: UITableView,cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell | |
{ | |
let cell:UITableViewCell = UITableViewCell(style:UITableViewCellStyle.Default, reuseIdentifier:"Cell") | |
cell.textLabel?.text = self.tableData[indexPath.row] | |
return cell | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment