import UIKit
class ViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
//MARK: - 懒加载
lazy var modelArr: NSMutableArray = {
let arr = NSMutableArray()
return arr
}()
lazy var tableView: UITableView = {
let tb = UITableView(frame: UIScreen.main.bounds, style: .plain)
tb.dataSource = self
tb.delegate = self
tb.rowHeight = 100
//注册cell
tb.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
return tb
}()
//MARK: - sysMethod
override func viewDidLoad() {
super.viewDidLoad()
self.view.addSubview(tableView)
}
//MARK: - UITableViewDelegate
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 10
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
//随机色
let red = CGFloat(arc4random_uniform(256))/CGFloat(255.0)
let green = CGFloat( arc4random_uniform(256))/CGFloat(255.0)
let blue = CGFloat(arc4random_uniform(256))/CGFloat(255.0)
cell?.backgroundColor = UIColor(red: red, green: green, blue: blue, alpha: 1.0)
return cell!
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 100
}
}
网友评论