ios - 如何在 tableView Swift 中使 Xib 页脚项目可点击
问题描述
我正在努力使我的页脚项目在 tableView 中可点击。在 tableView 中,我使用了两个不同的 Xib,并tableView - didSelect function
在单击时用作可扩展单元格。
1) 主要 Xib
2) Child_View - 页脚 Xib
现在在作为 childView 的页脚项目上 - 我也想进行可点击的操作,所以点击它会navigate to viewController
显示他们的详细信息。
- 由于 didSelect 已用于可扩展单元格,我该如何实现这一点?
附上三张图片
- 主要习题
- 展开 - 页脚项目(第二个 Xib)
- 突出显示的需要可点击
宣布 :var selectedIndex : Int! = -1
代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == selectedIndex{
selectedIndex = -1
}else{
selectedIndex = indexPath.row
}
tableView.reloadData()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if indexPath.row == selectedIndex
{
return UITableView.automaticDimension
}else{
return 71
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DownloadEntryViewCell", for: indexPath) as! DownloadEntryViewCell
let dic = Appdata?[indexPath.row]
var stackHeight:CGFloat = 0.0
cell.fileNameLabel.text = dic?.date
for i in Appdata ?? [] {
let child_view = Bundle.main.loadNibNamed("FooterView", owner: self, options: nil)?.first as! FooterView
child_view.projName.text = "\(i.projectName ?? "")" + " " + "\(i.subTitle ?? "")"
cell.stackViewFooter.addArrangedSubview(child_view)
stackHeight = stackHeight + 60.0
}
cell.stackViewFooter.heightAnchor.constraint(equalToConstant: stackHeight).isActive = true
return cell
}
图片:
解决方案
推荐阅读
- visual-studio-code - 使用键绑定在 VSCode 中执行预定义的 Find-Replace-All
- javascript - 默认情况下以折叠方式开始 HTML 行
- c - 无符号变量发生整数溢出
- sql - 如何在 SQL 中将日期分组为自定义周数?
- android - 不能使用任何比 1.5.3 更新的自动值版本
- node.js - 从 NodeJs 到 Erlang 应用程序的 RPC 调用
- javascript - 使用 ChangeDetectorRef 检测组件状态变化以便与材料步进器一起步进?
- ffmpeg - 在流 #0 (mp4) 中找不到编解码器 h264 的标签
- java - 微服务假装无限循环的调用?
- python - 如何通过 WebSocket 发送长时间运行的 Python 脚本的输出?