我正在使用以下機制來執行UITableView行顯示和隱藏。
class TableViewController: UITableViewController {
private var hiddenIndexPaths : Set<IndexPath> = []
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func toggle(_ sender: UISwitch) {
if sender.isOn {
show(1)
show(2)
} else {
hide(1)
hide(2)
}
tableView.beginUpdates()
tableView.endUpdates()
}
private func isHidden(_ indexPath: IndexPath) -> Bool {
hiddenIndexPaths.contains(indexPath)
}
private func hide(_ item: Int) {
hiddenIndexPaths.insert(IndexPath(item: item, section: 0))
}
private func show(_ item: Int) {
hiddenIndexPaths.remove(IndexPath(item: item, section: 0))
}
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
if isHidden(indexPath) {
return 0.0
}
return super.tableView(tableView, heightForRowAt: indexPath)
}
}
如您所見,它在 iPhone SE 模擬器中運行良好(在 iPhone SE 真實設備中也運行良好)
iPhone SE 模擬器

但是,在非 iPhone SE 模擬器(如 iPhone 13)中,一旦表格行被隱藏,就無法再顯示。請參考以下視頻。
iPhone 13 模擬器

我不確定它在 iPhone 13 真實設備中的行為,因為我無權訪問。
我想知道,你知道為什么會出現這樣的問題嗎?
如果您有興趣測驗,這里是完整的可行示例 - https://github.com/yccheok/show-hide-table-row-bug
測驗環境
- XCode 版本 14.0 (14A309)
- macOS 蒙特雷版本 12.6 (M1)
- 模擬器 iPhone 13、iOS 15
uj5u.com熱心網友回復:
要解決此問題,請替換:
return 0.0
和
return 0.01
在你的heightForRowAt方法中。
有關更多詳細資訊,請參閱此帖子。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/516012.html
標籤:IOS迅速苹果手机
上一篇:如何在靜音模式下停止聲音
