2017-05-10 53 views
0

我想在我的tableView上选择一个预定义的单元格。在viewDidLoad中()我加入这个代码选择单个表格视图行

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

这只有当我设置self.tableView.allowsMultipleSelection为true剂量的工作。否则,单元格未被选中。你有关于这个问题的想法。我也做了self.tableView.allowsSelection = true,仍然有问题。

回答

2

移动你的代码viewDidAppear:

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