gpt4 book ai didi

ios - 我不知道为什么在 swift3 中不调用 viewForHeaderInSection

转载 作者:搜寻专家 更新时间:2023-10-31 21:49:58 24 4
gpt4 key购买 nike

我不知道为什么 viewForHeaderInSection 在 swift3 中没有被调用。我在 UITableView 中添加了 heightForHeaderInSection 但不幸的是没有调用。请帮助我检查如何修复它。

enter image description here

func numberOfSectionsInTableView(_ tableView: UITableView) -> Int {
return 3
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch (section) {
case 0:
return homeStrs.count
case 1:
return accountStrs.count
case 2:
return otherStrs.count
default:
return otherStrs.count
}
}

func tableView(_ tableView: UITableView, cellForRowAtIndexPath indexPath: IndexPath) -> UITableViewCell {
let cell = menuTable.dequeueReusableCell(withIdentifier: "MenuCell", for: indexPath) as! MenuCell
cell.layoutMargins = UIEdgeInsets.zero;
cell.lbNoti.isHidden = true
switch ((indexPath as NSIndexPath).section) {
case 0:
cell.lbMenuTitle?.text = homeStrs[(indexPath as NSIndexPath).row]
cell.imgIcon.image = UIImage (named: homeImgStrs[(indexPath as NSIndexPath).row])
case 1:
cell.lbMenuTitle?.text = accountStrs[(indexPath as NSIndexPath).row]
cell.imgIcon.image = UIImage (named: accountImgStrs[(indexPath as NSIndexPath).row])
case 2:
cell.lbMenuTitle?.text = otherStrs[(indexPath as NSIndexPath).row]
cell.imgIcon.image = UIImage (named: otherImgStrs[(indexPath as NSIndexPath).row])
default:
cell.lbMenuTitle?.text = "Other"
}

return cell
}

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
switch (section) {
case 1:
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.menuTable.frame.size.width, height: 30))
let menuHeaderLabel = UILabel(frame: CGRect(x: 20, y: 0, width: self.menuTable.frame.size.width, height: 28))
menuHeaderLabel.text = "Account Settings"
headerView.addSubview(menuHeaderLabel)
return headerView
case 2:
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.menuTable.frame.size.width, height: 30))
let menuHeaderLabel = UILabel(frame: CGRect(x: 20, y: 0, width: self.menuTable.frame.size.width, height: 28))
menuHeaderLabel.text = "Others"
headerView.addSubview(menuHeaderLabel)
return headerView
default:
let headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.menuTable.frame.size.width, height: 0))
return headerView
}
}

最佳答案

如果其他人遇到同样的问题......在 viewDidLoad 中添加这一行调用委托(delegate)方法因此使标题出现:

self.tableView.estimatedSectionHeaderHeight = 80

关于ios - 我不知道为什么在 swift3 中不调用 viewForHeaderInSection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40414498/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com