class serviceHallViewController: UIViewController ,UITableViewDelegate ,UITableViewDataSource {
var tableView :UITableView?
override func viewDidLoad() {
super.viewDidLoad()
//self.title = "MySwift"
setupViews()
// Do any additional setup after loading the view.
}
func setupViews()
{
//初始化tableview并设置frame
self.tableView = UITableView(frame:self.view!.frame)
//设置tableview的代理对象
self.tableView!.delegate = self
self.tableView!.dataSource = self
self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier:"cell")
//将tableview添加到view试图上
self.view?.addSubview(self.tableView!)
}
func tableView(tableView:UITableView, numberOfRowsInSection section:Int) -> Int
{
return 20;
}
// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)
func tableView(tableView:UITableView, cellForRowAtIndexPath indexPath:NSIndexPath) -> UITableViewCell
{
let cell = tableView .dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath)as! UITableViewCell
cell.textLabel!.text = String(format:"%i", indexPath.row+1)
return cell
}
转载于:https://my.oschina.net/227/blog/468648