import UIKit
class ViewController:UIViewController,UITableViewDataSource {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view,typically from a nib.
let screenRect = UIScreen.main.bounds
let tableRect = CGRect(x:0, y:20, width:
screenRect.size.width, height:screenRect.size.height - 20)
let tableView = UITableView(frame:tableRect)
tableView.dataSource = self
self.view.addSubview(tableView)
}
func tableView(_ tableView:UITableView,numberOfRowsInSection section:Int) -> Int{
return 20
}
func tableView(_ tableView:UITableView,cellForRowAt indexPath:IndexPath) -> UITableViewCell {
let identifier = “reusedCell”
var cell =tableView.dequeueReusableCell(withIdentifier:identifier)
if(cell == nil)
{
cell = UITableViewCell(style:UITableViewCellStyle.default, reuseIdentifier:identifier)
}
cell风纠?.textLabel怕磨?.text = “命運(yùn)負(fù)責(zé)洗牌笔横,玩牌的是我們自己!”
return cell据过!
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//UITableViewDatasource的代理方法
// cellForRowAtIndexPath