我在代碼中有一個頁眉和一個頁腳。我遇到的問題是當前部分的頁腳阻礙了該部分中的最后一個單元格。其次,如何在當前節頁腳和下一節頁眉之間添加空白行?
標頭代碼:
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return myTitles[section]
}
頁腳代碼:
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return("Total Emojis: \(emojis[section].count)")
}
uj5u.com熱心網友回復:
您可以將視圖用于頁眉和頁腳,而不是titleForHeaderInSection
and titleForFooterInSection
。
例如:
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 18))
let label = UILabel(frame: CGRect(x: view.centerX - 50, y: view.centerY, width: 100, height: 40))
label.text = myTitles[section]
label.textAlignment = .center
view.addSubview(label)
return view
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 60
}
對于頁腳,您可以使用相同的概念。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/454099.html
上一篇:相機視圖隱藏TabView