gpt4 book ai didi

ios - TableView 在 Swift 中丢失选定的行

转载 作者:搜寻专家 更新时间:2023-11-01 06:23:15 25 4
gpt4 key购买 nike

我有一个导航 Controller 和两个附加到它的 View Controller ViewController1ViewController2。当This is the code snippet where I set the selected row

  func questions()
{ // Initalizations
var ns = defaults.integerForKey(qwre)
let indexPath = NSIndexPath(forRow: ns, inSection: 0)
self.tableView.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: UITableViewScrollPosition.None)
}

每当加载 ViewController1 时,该行都被选中。

这是我的函数 viewdidLoad()

override func viewDidLoad() {
questions()
}

现在的问题是每当我从 ViewController2 返回到 ViewController1 时。我没有选择行。显然 viewDidLoad() 没有被调用。我应该将代码保存在哪里,以便在我返回时调用 questions

最佳答案

您可以使用 viewDidAppear() 来调用您的方法

override func viewDidAppear(animated: Bool) {
questions()
}

HTH,享受编码吧!

关于ios - TableView 在 Swift 中丢失选定的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29668274/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com