0
我有一個小問題,我的靜態tableview。我有一個彈出窗口顯示爲我的網格選項。我要救我的靜態TableView中的狀態(indexPath),但似乎它不工作,下面是我的代碼片段:Swift:保存並顯示選定的indexPath在靜態表視圖
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
var currSelected: IndexPath?
let section = indexPath.section
let numberOfRows = tableView.numberOfRows(inSection: section)
for row in 0..<numberOfRows {
if let cell = tableView.cellForRow(at: NSIndexPath(row: row, section: section) as IndexPath) {
cell.accessoryType = row == indexPath.row ? .checkmark : .none
tableView.deselectRow(at: indexPath, animated: false)
currSelected = indexPath
if section == 2 {
tableView.deselectRow(at: indexPath, animated: false)
cell.accessoryType = .none
}
else {
delegate?.option(lastSelected: currSelected!)
NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reload"), object: nil)
}
}
}
}
我試圖用delegate
扔lastSelected
(最後indexPath)以前控制器並將其發送回Pop Over Controller,然後我就得到了它。但我不知道使用lastSelected顯示覆選標記。而prepare for cell at
函數需要一個重用單元的標識符,但我不使用它。
我已閱讀this以顯示覆選標記但未保存狀態。我也讀過this,但也一樣。任何建議/答案將幫助我。在此先謝謝
其唯一的保存一個選中標記。我有2個部分,不能chekced,所以我需要2複選標記,如果lastSelected有兩個複選標記 –
然後,您需要存儲IndexPaths數組而不是IndexPath變量,並在'willDisplayCell',通過該數組循環 – Malik
其工作與分離索引路徑。接受爲有用的sugest,我會更新我的最終代碼。提前致謝 –