我有一个tableViewController,我的数据源运行良好,但无法以编程方式选择一行。
我尝试过:
class DocumentTableViewController: UITableViewController {
override func viewDidLoad() {
super.viewDidLoad()
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: true, scrollPosition: UITableViewScrollPosition(rawValue: 0)!)
}
}
当我运行时,tableView不会选择任何内容。 我该如何解决?
答案 0 :(得分:2)
您的电话线很早就尝试了
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: true, scrollPosition: UITableViewScrollPosition(rawValue: 0)!)
}
或viewDidLoad
内的
tableView.reloadData()
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: true, scrollPosition: UITableViewScrollPosition(rawValue: 0)!)
答案 1 :(得分:0)
快速5:
tableView.selectRow(at: IndexPath(row: 0, section: 0), animated: true, scrollPosition: UITableView.ScrollPosition(rawValue: 0)!)