IOS UITableView UITableViewCell controls

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 = “命运负责洗牌,玩牌的是我们自己!”
return cell!
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}

// UITableViewDatasource the proxy method


9967595-e769c9c432c71a9a.png
image.png

// cellForRowAtIndexPath


9967595-8461e678895fd95b.png
image.png
9967595-d7bea370b17f45d3.png
image.png

Guess you like

Origin blog.csdn.net/weixin_34037515/article/details/90866443