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
?
答案 0 :(得分:0)
您可以从tableView
let header = tableView.headerViewForSection(section: sender.tag) as! GuideheaderTableViewCell
header?.dwnldBtn.isHidden = false