在加载

时间:2017-01-07 20:51:00

标签: ios swift uitableview

我在带有NavigationController的UITableViewController中默认选择第一行时看到了多个线程,我使用了一些社区答案中找到的代码,但它仍然不适合我。 / p>

override func viewDidAppear(_ animated: Bool) {
    let indexPath = IndexPath(row: 0, section: 0)
    tableView.selectRow(at: indexPath as IndexPath, animated: false, scrollPosition: .middle)
}

它只突出显示我作为indexPath放置的任何行,但它实际上并没有转到与该indexPath关联的视图。我觉得它已经连接好了,因为当我确实点击该行时它会进入视图。我在这里错过了一步吗?

提前致谢!

1 个答案:

答案 0 :(得分:0)

  

调用此方法不会导致委托接收   tableView(:willSelectRowAt :)或tableView(:didSelectRowAt :)消息,   它也不会发送UITableViewSelectionDidChange通知   观察者。

您必须致电UITableview的委托didSelectRowAt方法。

相关问题