我有一个导航 Controller 和两个附加到它的 View Controller ViewController1
和 ViewController2
。当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/