class DDBaseViewController: UIViewController,UITableViewDelegate,UITableViewDataSource {
var _dataSoure = NSMutableArray()
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.red
for index in 0...10 {
let title = String(index)
_dataSoure.add(title)
}
let frame = CGRect(x: 0, y: 64, width: self.view.bounds.size.width, height: self.view.bounds.size.height)
let tableView = UITableView(frame: frame, style: .plain)
tableView.delegate = self;
tableView.dataSource = self;
self.view.addSubview(tableView)
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return _dataSoure.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let identifier = "identifierCell"
var cell = tableView.dequeueReusableCell(withIdentifier: identifier)
if cell == nil {
cell = UITableViewCell(style: .default, reuseIdentifier: identifier)
}
cell?.textLabel?.text = String(describing: _dataSoure[indexPath.row])
return cell!
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
}
Swift UITableView基础
最新推荐文章于 2024-04-04 21:36:29 发布