У меня есть один UITableView, и у него также есть раздел заголовка. На основании раздела заголовка у них есть соответствующие данные.
Каждый раздел заголовка имеет одну кнопку, которую можно нажимать по желанию пользователя.
нажмите на него, это потратит UITableView
Я использую код ниже
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerCell = Bundle.main.loadNibNamed("DashTableViewCell", owner: self, options: nil)?.first as! DashTableViewCell
headerCell.lblQueryType.text = queriesArray[section]
headerCell.btnExpendable.addTarget(self, action: #selector(expendSection), for: .touchUpInside)
headerCell.btnExpendable.tag = section
return headerCell
}
@objc func expendSection(button: UIButton) {
var indexPaths = [IndexPath]()
let section = button.tag
if button.tag == 0 {
QueriesStructArray[section].isExpended = !QueriesStructArray[section].isExpended
for row in QueriesStructArray.indices {
let indexPath = IndexPath(row: row, section: section)
indexPaths.append(indexPath)
}
} else if button.tag == 1 {
MyQueriesStructArray[section].isExpended = !MyQueriesStructArray[section].isExpended
for row in MyQueriesStructArray.indices {
let indexPath = IndexPath(row: row, section: section)
indexPaths.append(indexPath)
}
}
if button.tag == 1 {
if MyQueriesStructArray[section].isExpended == true {
tblProjectDashBoard.deleteRows(at: indexPaths, with: .fade)
} else {
tblProjectDashBoard.insertRows(at: indexPaths, with: .fade)
}
}
else if button.tag == 0 {
if QueriesStructArray[section].isExpended == true {
tblProjectDashBoard.deleteRows(at: indexPaths, with: .fade)
} else {
tblProjectDashBoard.insertRows(at: indexPaths, with: .fade)
}
}
}
func numberOfSections(in tableView: UITableView) -> Int {
return queriesArray.count
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == 0 {
if QueriesStructArray[section].isExpended == true {
return 0
}
return QueriesStructArray.count
} else if section == 1 {
if MyQueriesStructArray[section].isExpended == true {
return 0
} else {
return MyQueriesStructArray.count
}
}
return 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "ProjectDashTableViewCell", for: indexPath) as? ProjectDashTableViewCell {
if indexPath.section == 0 {
cell.lblTitle.text = QueriesStructArray[indexPath.row].queries
return cell
} else if indexPath.section == 1 {
cell.lblTitle.text = MyQueriesStructArray[indexPath.row].myQueries
return cell
}
}
return UITableViewCell()
}
все работает нормально, но когда я нажал "Shared Queries"
кнопку затем раздел «Мои запросы» получил скрыть, что не так, я не могу
найти проблему в коде