开发者

Selecting A Row In An NSTableView Programmatically

I want to开发者_StackOverflow中文版 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)?


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.

What you’re looking for is very straight forward.

Objective-C

NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:1];
[tableview selectRowIndexes:indexSet byExtendingSelection:NO];

Swift 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜