import UIKit
class ViewController: UIViewController ,UITableViewDelegate,UITableViewDataSource{
let arr = ["1","2","3","4","5","6"]
let tableView = UITableView.init(frame: UIScreen.main.bounds, style: .grouped)
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
self.view.addSubview(self.tableView)
// Do any additional setup after loading the view, typically from a nib.
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = Bundle.main.loadNibNamed("MineTableViewCell", owner: nil, options: nil)?.last as! MineTableViewCell
cell.titleL.text = arr[indexPath.section]
return cell
}
func numberOfSections(in tableView: UITableView) -> Int {
return arr.count
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 200
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
let cell = Bundle.main.loadNibNamed("MineTableViewCell", owner: nil, options: nil)?.last as! MineTableViewCell
cell.titleL.text = arr[section]
cell.backgroundColor = UIColor.red
return cell
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let cell = Bundle.main.loadNibNamed("MineTableViewCell", owner: nil, options: nil)?.last as! MineTableViewCell
cell.titleL.text = arr[section]
cell.backgroundColor = UIColor.green
return cell
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 30
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 30
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
转载于:https://my.oschina.net/wayzhu/blog/1563163