我将从MSSQL中提取的数据分配给sectionNames和sectionDetay。我用sectionNames绘制主题的标题,并用sectionDetay显示主题的内容。我放了一个箭头来显示主题的内容。当按箭头键时,他必须显示主题的内容。当我单击当前代码中的箭头时,没有任何变化。单击“箭头”时如何获得主题的详细信息?当我单击“箭头”时,无法显示该主题的详细信息,该主题目前没有任何功能。我该怎么办?
class SSSTableViewController: UITableViewController {
var sectionNames: [String] = []
var sectionDetay: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
makaleBaşlık()
makaleDetay()
tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableView.automaticDimension
self.title = "SSS"
}
func makaleBaşlık(){
let client = SQLClient.sharedInstance()!
client.connect("...", username: "...", password: "...", database: "...") { success in
client.execute("SELECT ... FROM ... WHERE ...", completion: { (_ results: ([Any]?)) in
for table in results as! [[[String:AnyObject]]] {
for row in table {
for (_, value) in row {
if let intVal = value as? String {
self.sectionNames.append(String(intVal))
}
} } }
DispatchQueue.main.async {
self.tableView.reloadData()
}
client.disconnect()
})
}
}
func makaleDetay(){
let client = SQLClient.sharedInstance()!
client.connect("...", username: "...", password: "nP8Ym%2sA", database: "...") { success in
client.execute("SELECT ... FROM ... WHERE ...", completion: { (_ results: ([Any]?)) in
for table in results as! [[[String:AnyObject]]] {
for row in table {
for (_, value) in row {
if let intVal = value as? String {
let string = intVal
if let result = string.htmlAttributedString?.string { self.sectionDetay.append(String(result))
}
}
} } }
DispatchQueue.main.async {
self.tableView.reloadData()
}
client.disconnect() }) }
}
extension SSSTableViewController {
override func numberOfSections(in tableView: UITableView) -> Int {
return sectionDetay.count
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: CollapsibleTableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell") as? CollapsibleTableViewCell ??
CollapsibleTableViewCell(style: .default, reuseIdentifier: "cell")
// let item: ItemDetay = sections[indexPath.section].items[indexPath.row]
cell.nameLabel.text = "SSS"
cell.detailLabel.text = sectionDetay[indexPath.section]
return cell
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
// Header
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: "header") as? CollapsibleTableViewHeader ?? CollapsibleTableViewHeader(reuseIdentifier: "header")
header.titleLabel.text = sectionNames[section]
header.arrowLabel.text = ">"
let tap = UITapGestureRecognizer(target: self, action: #selector(tapFunction))
header.arrowLabel.isUserInteractionEnabled = true
header.arrowLabel.addGestureRecognizer(tap)
header.setCollapsed(true)
header.section = section
header.delegate = self
return header
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 44.0
}
override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 1.0
}
}
extension SSSTableViewController: CollapsibleTableViewHeaderDelegate {
func toggleSection(_ header: CollapsibleTableViewHeader, section: Int) {
// let collapsed = !sections[section].collapsed
// Toggle collapse
// sections[section].collapsed = collapsed
header.setCollapsed(false)
// Reload the whole section
tableView.reloadSections(NSIndexSet(index: section) as IndexSet, with: .automatic)
}
}