【发布时间】:2015-07-11 02:15:30
【问题描述】:
我在 viewDidLoad() 中使用下面的代码来尝试预先选择 tableView 对象 (tblProjectNumber) 中的表格行。编译或运行时没有错误。
一切加载正常,一旦加载视图,我可以通过鼠标单击选择表格行而不会出现任何问题。但是,我无法加载预先选择了所需默认行的视图。我在 viewDidLoad() 中尝试了以下代码(最后三行参考)。数据加载时,tableView 不显示选定的行,也不滚动 index(100) 处的行。
override func viewDidLoad() {
super.viewDidLoad()
self.view.wantsLayer = true
self.view.layer?.backgroundColor = NSColor.windowBackgroundColor().CGColor
self.view.window?.title = "Project Detail Module"
self.view.window?.titleVisibility
// sort the list of project numbers so that they display correctly when the view is first loaded
self.sortProjectNumberArray()
self.loadProjectRowDataArray()
self.sortPPRFilesForLatestDate()
// pre-select table row to load on initial display of the tableView
let index = NSIndexSet(index: 100)
self.tblProjectNumber.scrollRowToVisible(100)
self.tblProjectNumber.selectRowIndexes(index, byExtendingSelection: true)
}
答案在这里:
- Select row in tableView programmatically by other method beside calling their indexPath
- Select tableview row programmatically
- Xcode - Swift Programmatically select tablecell
已提供帮助,但我无法解决问题。此外,最后一个链接中使用的对 selectRowAtIndexPath 的调用在 Swift 中似乎不可用,因此它对我也不起作用。
【问题讨论】:
标签: macos swift nstableview