我试图通过代码设置表视图中节的页脚和页眉的高度,但不起作用.当我在故事板上做的时候,它工作得很好.
这是我的代码
import UIKit
class MyTableViewController: UIViewController {
@IBOutlet weak var myTable : UITableView!
let spacing : CGFloat = 20
override func viewDidLoad() {
super.viewDidLoad()
myTable.delegate = self
myTable.dataSource = self
}
}
extension MyTableViewController : UITableViewDelegate, UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = myTable.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
cell.textLabel?.text = "Random text"
cell.accessoryType = .detailButton
return cell
}
func numberOfSections(in tableView: UITableView) -> Int {
return 5
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return spacing
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return spacing
}
}
代码的输出:
我想在牢房里放些垫子.