刚开始写控件,感觉无从下手,这只是一个简版的,会陆续完善这个。
import UIKit
class ViewController: UIViewController ,UITableViewDelegate, UITableViewDataSource
{
var tableView : UITableView?
var cell : UITableViewCell?
override func viewDidLoad()
{
super.viewDidLoad()
self.tableView = UITableView(frame:CGRectMake(30,20,240,320))
self.tableView!.delegate = self
self.tableView!.dataSource = self
self.tableView!.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cellIdentifier")
self.view?.addSubview(self.tableView)
}
func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int
{
return 5
}
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!
{
let cell = tableView.dequeueReusableCellWithIdentifier("cellIdentifier", forIndexPath: indexPath) as UITableViewCell
cell.textLabel.text = String(format: "%i", indexPath.row)
cell.textLabel.textAlignment = NSTextAlignment.Center;
return cell
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!)
{
println("indexRow = ",indexPath.row)
}
override func didReceiveMemoryWarning()
{
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}