-
-
Save nbomberger/2c2e7da1e14250ba6067 to your computer and use it in GitHub Desktop.
UITableView example in iOS Playground with XCode 6 beta
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
// 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() //Not needed | |
ctrl.view |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment