0
我正在扩展和折叠表格视图单元格。目前的情况很好,假设Row-0被挖掘,在索引-1处添加新行并显示为展开,并且当再次敲击Row-0时,展开的索引-1被折叠。如果Row-0处于展开状态,并且即使我点击另一个Row,该行也会展开,同时保持两个打开状态。 这是我想要更改的内容,我想要合同在打开另一行时打开的其他任何行。即一行应该一次打开。请参阅下面的代码中的ref,我尝试使用数组来检测哪一行当前被展开,只有当我们顺序执行时,这才有效,否则它将开始删除合同行。任何帮助将不胜感激。迅速扩展和合同UITableView第一行swift
谢谢!
public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
{
if expandCellArray.object(at: indexPath.row) as! String == "contract"
{
for i in 0 ..< self.expandCellArray.count
{
if expandCellArray.object(at: i) as! String == "expanded"
{
self.contractCell(tableView: tableView, index: i)
self.expandCellArray.replaceObject(at: i, with: "contract")
print("Updated Expand Cell array",expandCellArray)
}
}
self.expandCell(tableView: tableView, index: indexPath.row)
self.expandCellArray.replaceObject(at: indexPath.row, with: "expanded")
print("Updated Expand Cell array",expandCellArray)
}
else
{
self.contractCell(tableView: tableView, index: self.selectedIndexPath.row)
}
}
功能扩展行
private func expandCell(tableView: UITableView, index: Int)
{
if (dataArray[index]?.title) != nil {
dataArray.insert(nil, at: index + 1)
myTableView.insertRows(at: [IndexPath(row: index + 1, section: 0)], with: .none)
}
}
功能到契约行
private func contractCell(tableView: UITableView, index: Int)
{
if (dataArray[index]?.title) != nil {
dataArray.remove(at: index + 1)
myTableView.deleteRows(at: [IndexPath(row: index + 1, section: 0)], with: .none)
}
}