我下面的代码在用户触摸 TableView 中的一行时以编程方式呈现 View Controller 。代码位于“didSelectRowtIndex”路径中, TableView 位于 ViewController 类中,我在其中实现了 TableView 委托(delegate)。我遇到的问题是我试图呈现的 View Controller 只出现在表格 View 行的第二次触摸上。但是,当父 View Controller 首次加载时,它们会在第一次触摸时出现。下面是“didSelectRowAtIndexPath”中用于显示两个 subview Controller 的代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
let stockTable = StockTableVC()
self.present(stockTable, animated: false, completion: nil)
}
else indexPath.row == 1 {
let accountTable = AccountTableVC()
self.present(accountTable, animated: false, completion: nil)
}
...
每次选择行时都会调用上述两种当前 View Controller 方法,但有时不会在第一次选择时显示(或者至少它们不可见)。对这个谜团的任何帮助都会很棒。
-谢谢
最佳答案
您必须先取消选择该行。在演示之前添加:
tableView.deselectRow(at: indexPath, animated: false)
的确,这对我来说也是一个谜。但这帮助我在不久前让它发挥作用,我希望它也对你有用。
关于ios - ViewController 演示文稿 Swift 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42258598/