Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting A Row In An NSTableView Programmatically

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)?

like image 267
Joshua Avatar asked Dec 18 '09 15:12

Joshua


1 Answers

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.

like image 173
Brad G Avatar answered Sep 20 '22 06:09

Brad G