使用TableView

关键代码如下:

 1 import UIKit
 2 
 3 class MyTV: UITableView ,UITableViewDataSource{
 4 
 5     let table_cell=1
 6     
 7     var array=["尽子轨","渣渣将","swift"]
 8     
 9     init(coder aDecoder:NSCoder!){
10         super.init(coder:aDecoder)
11         self.dataSource=self
12     }
13     init(frame: CGRect) {
14         super.init(frame: frame)
15         // Initialization code
16     }
17     func numberOfSectionsInTableView(tableView: UITableView!) -> Int {
18         return 1
19     }
20     
21     func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
22         var cell : AnyObject!=tableView.dequeueReusableCellWithIdentifier("cell")
23         var label=cell.viewWithTag(table_cell) as UILabel
24         label.text=array[indexPath.row]
25         return cell as UITableViewCell
26     }
27     
28     func tableView(tableView: UITableView!, numberOfRowsInSection section: Int) -> Int {
29         return 3
30     }
31     
原文地址:https://www.cnblogs.com/newworldcom/p/4458329.html