gpt4 book ai didi

swift - 如何在表格 View 中全局获取标题单元格

转载 作者:行者123 更新时间:2023-11-28 07:42:44 26 4
gpt4 key购买 nike

override  func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

let myIndexPath = IndexPath(row: 0, section: section)

let header = tableView.dequeueReusableCell(withIdentifier: "header", for: myIndexPath) as? GuideheaderTableViewCell

header?.dwnldBtn.isHidden = true

header?.dwnldBtn.tag = section
header?.dwnldBtn.addTarget(self, action:#selector(headerPressed(_:)), for:.touchUpInside)

return header?.contentView
}


@objc func headerPressed(_ sender: AnyObject) {

print("Header tapped %@", sender.tag)
let indexPath = IndexPath(row: 0, section: sender.tag)

if hiddenSections.contains(sender.tag)
{
hiddenSections.remove(at: hiddenSections.index(of: sender.tag)!)

tableView.reloadSections(NSIndexSet(index: sender.tag) as IndexSet, with: .automatic)

tableView.scrollToRow(at: indexPath, at: UITableViewScrollPosition.top, animated: true)
}
else
{
hiddenSections.append(sender.tag)
tableView.reloadSections(NSIndexSet(index: sender.tag) as IndexSet, with: .automatic)
}

}

我在标题中隐藏了 dwnldBtn,如何在“headerPressed”上显示 dwnldBtn

最佳答案

您可以从 tableView 获取节标题

let header = tableView.headerViewForSection(section: sender.tag) as! GuideheaderTableViewCell
header?.dwnldBtn.isHidden = false

关于swift - 如何在表格 View 中全局获取标题单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51766372/

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