选择一个tableView行

时间:2017-05-10 13:31:57

标签: ios uitableview tableviewcell

我正在尝试在tableView上选择一个预定义的单元格。在viewDidLoad()上我添加了这段代码

tableView.selectRow(at: selectionIndexPath, animated: true, scrollPosition: .none)

此剂量仅在我将self.tableView.allowsMultipleSelection设置为true时才起作用。否则,未选择单元格。你对这个问题有所了解吗?我也做过self.tableView.allowsSelection = true但仍有问题。

1 个答案:

答案 0 :(得分:2)

将您的代码移至viewDidAppear:

override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        tableView.selectRow(at: selectionIndexPath, animated: true, scrollPosition: .none)
}
相关问题