objective-c 以编程方式在 NSTableView 中选择一行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1928716/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selecting A Row In An NSTableView Programmatically
提问by Joshua
I want to Select A Row in my table view programmatically, I believe I would use selectRowIndexes:byExtendingSelection:(is this a delegate method?). The other thing is how would I use that method to select the second row (in programming terms row 1)?
我想以编程方式在我的表视图中选择一行,我相信我会使用selectRowIndexes:byExtendingSelection:(这是一种委托方法吗?)。另一件事是我将如何使用该方法来选择第二行(在编程术语中,第 1 行)?
回答by Brad Goss
Joshua, make sure to use the developers documentation to determine whether or not it's a delegate method. If it were a delegate method, it would be mentioned in the docs for NSTableViewDelegate.
Joshua,请务必使用开发人员文档来确定它是否是委托方法。如果它是一个委托方法,它会在 NSTableViewDelegate 的文档中提到。
What you're looking for is very straight forward.
你要找的东西很简单。
Objective-C
目标-C
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:1];
[tableview selectRowIndexes:indexSet byExtendingSelection:NO];
Swift 2
斯威夫特 2
let indexSet = NSIndexSet(index: 1)
tableView.selectRowIndexes(indexSet, byExtendingSelection: false)
Again. Make sure to look up the method selectRowIndexes:byExtendingSelection in the docs to see what parameters it needs. It says an NSIndexSet is needed. Then look up NSIndexSet and you'll discover how to use that.
再次。确保在文档中查找方法 selectRowIndexes:byExtendingSelection 以查看它需要哪些参数。它说需要一个 NSIndexSet。然后查找 NSIndexSet,您将发现如何使用它。

