gpt4 book ai didi

swift - 当 uitableview 部分折叠时,单元格中的按钮不会隐藏

转载 作者:行者123 更新时间:2023-11-30 11:32:13 68 4
gpt4 key购买 nike

我正在实现一个带有部分和可折叠标题的UITableView。该部分的单元格具有标签和按钮。当我折叠标题时,标签已折叠,但按钮保持空闲(未隐藏)。

我需要一个实现,其中按钮在单元格展开时出现,在单元格折叠时隐藏。我使用了一个自定义单元格,该单元格位于堆栈 View 内。在 this picture箭头代表表格部分标题 View ,单选按钮在折叠后必须隐藏。

这是代码:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if (sections[indexPath.section].expanded)
{
return 244
}
else
{

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

let header = ExpandableDashboardView()
print("title\(sections[section].title)")
header.customInit(title: sections[section].title, section: section, delegate: self,isOpen:sections[section].expanded)
return header

}

func toggleSection(header: ExpandableDashboardView, section: Int) {
sections[section].expanded = !sections[section].expanded

settingsTable.beginUpdates()
if sections[section].expanded == true
{

header.changeInit(title: sections[section].title, section: section, delegate: self)
}
else
{
header.customInit(title: sections[section].title, section: section, delegate: self, isOpen: sections[section].expanded)


}

class ExpandableDashboardView: UITableViewHeaderFooterView{
var delegate : ExpandableDashboardDelegate!
var section:Int!
var image = UIImage()

override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
self.addGestureRecognizer(UITapGestureRecognizer(target:self,action:#selector(selectDashboardHeader)))
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func customInit(title:String,section:Int,delegate:ExpandableDashboardDelegate,isOpen:Bool)
{
// if isOpen == true{
//// self.textLabel?.text = "\u{25B6} \(title)"
// self.textLabel?.text = "\u{25BC} \(title)"
// }
// else{
// self.textLabel?.text = "\u{25BC} \(title)"
// }
// self.textLabel?.textColor = UIColor.black

self.textLabel?.text = "\u{25B6} \(title)" //02C3
self.section = section
self.delegate = delegate
layoutSubviews()

}

func changeInit(title:String,section:Int,delegate:ExpandableDashboardDelegate)
{
self.textLabel?.textColor = UIColor.black

self.textLabel?.text = "\u{25BC} \(title)"
self.section = section
self.delegate = delegate
layoutSubviews()
}

func selectDashboardHeader(gestureRecognizer:UIGestureRecognizer)
{
let cell = gestureRecognizer.view as! ExpandableDashboardView
delegate.toggleSection(header: self , section: cell.section)
print("section\(cell.section)")
}
override func layoutSubviews() {
super.layoutSubviews()
self.textLabel?.textColor = UIColor.init(red: 17.0/255.0, green: 83.0/255.0, blue: 168.0/255.0, alpha: 1.0)
self.contentView.backgroundColor = UIColor.init(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
}

最佳答案

我发现了后面的问题。检查按钮界面生成器中的“剪辑到边界”。这将使按钮隐藏。

关于swift - 当 uitableview 部分折叠时,单元格中的按钮不会隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50135819/

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