【发布时间】:2019-03-15 05:37:59
【问题描述】:
我有一个表格视图,它有 2 个部分和每个部分下方的一些单元格(可以是动态的)显示相关数据。
这是我为显示数据而编写的代码...
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
return recentUsers?.count
} else {
return groupNameArray?.count
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return 2
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
if section == 0 {
return " CHAT LIST"
} else {
return " GROUPS"
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! RecentMessageCell
cell.tag = indexPath.row
if indexPath.section == 0 {
if let user = recentChatUsers?[indexPath.row] {
cell.idLabel?.text = user.id
}
} else {
if groupNameArray.isEmpty == false {
let grpArr = groupNameArray[indexPath.row]
cell.userNameLabel?.text = grpArr.grpname
}
}
return cell
}
现在我想要实现的是,如果我点击第一部分,它应该展开并显示它包含的单元格,第二个单元格也应该发生同样的情况。再次单击每个部分应隐藏已展开的单元格。
我确实在互联网上搜索了解决方案。但是尽管有可用的资源,但我无法为我的问题找到太多帮助......
【问题讨论】:
-
你可以按照这个例子github.com/kamirana4/SwiftComponents
-
不,它不是第三方。看
ExpandableTableViewExample的实现就自己动手吧。 -
ya..:) 看过了.. 因此删除了我的评论...:)
标签: ios swift uitableview