ios - 在 tapGesture 上更新 UITableViewHeaderFooterView 的标签
问题描述
我正在开发可折叠-可扩展的 Tableview 单元格,在该单元格中我为 UITableViewHeaderFooterView 创建了单独的类和 xib,并将两者相互链接。Xib 视图包含两个标签,一个用于标题,一个用于+ 或 -以指示部分已折叠或展开。现在在我的一个视图控制器中,我已经编写了所有必要的 tableview 方法,下面是相同的代码。
var sections = [
Section(Title: "Sec 1", Indicator : "-" , expanded : true, moview : ["Simba1","TaleSpin1"]),
Section(Title: "Sec 2", Indicator : "+" ,expanded : false, moview : ["Simba2","TaleSpin2"]),
Section(Title: "Sec 3", Indicator : "+" ,expanded : false, moview : ["Simba3","TaleSpin3"]),
Section(Title: "Sec 4", Indicator : "+" ,expanded : false, moview : ["Simba4","TaleSpin4"])
]
var selectIndexPath: IndexPath!
override func viewDidLoad() {
super.viewDidLoad();
selectIndexPath = IndexPath(row: -1, section: -1)
tableView.register(UINib(nibName: "HeaderView", bundle: nil), forHeaderFooterViewReuseIdentifier: "HeaderView");
}
override func numberOfSections(in tableView: UITableView) -> Int {
return sections.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return sections[section].movie.count
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if sections[indexPath.section].expanded {
return 44
} else {
return 0
}
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 2
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
//let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "ExpandableHeader") as! ExpandableHeaderView;
let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "HeaderView") as! HeaderView
headerView.customInit(title: sections[section].Title , indicator: sections[section].Indicator , section: section, delegate: self)
return headerView
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "labelCell")!;
cell.textLabel?.text = sections[indexPath.section].movie[indexPath.row];
return cell
}
func toggleSection(header: HeaderView, section: Int) {
print("expanded: \(!sections[section].expanded)");
sections[section].expanded = !sections[section].expanded
sections[section].Indicator = "+"
tableView.beginUpdates()
for i in 0 ..< sections[section].movie.count {
tableView.reloadRows(at: [IndexPath(row: i, section: section)], with: .automatic)
}
tableView.endUpdates()
}
我想根据用户点击时部分是折叠还是展开来更改标签+或-。我尝试sections[section].Indicator = "+"
在函数中添加这一行toggleSection
但没有用。
任何帮助将不胜感激。
解决方案
推荐阅读
- javascript - 如何添加添加到 dropzone 的文件并将它们发送到 ajax 请求中,就好像它们是输入文件字段一样
- javascript - 如何使用 array.push() 函数复制数组而没有重复的键值?
- ssis - Kingswaysoft SSIS 使用预定义的 GUID 创建记录
- python - Python Flask:找不到在 SelectForm (Flask WTF) 中设置默认值的方法
- django - Django 分组和过滤、排序
- mysql - MYSQL 12 小时时间格式卡在前导 0,并且不会转换为 24 小时格式
- angular - 行为主题不会在更改 Async Angular 10 时更新
- python - 熊猫 | 创建新的 DataFrame 合并具有相同值的行
- augmented-reality - AR 模式 A 帧中的点击事件
- c# - SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.57 SMTP;Office 365 错误