I want to Select A Row in my table view programatically, 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)?
views:
104answers:
1
+3
A:
Joshua, make sure to use the developers documentation to determine weather or not it's a delegate method. If it were a delegate method, it would be mentioned under the NSTableViewDelegate docs.
What your looking for is very straight forward.
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:1];
[tableview selectRowIndexes:indexSet byExtendingSelection:NO];
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 lookup NSIndexSet and you'll discover how to use that.
Brad Goss
2009-12-18 15:29:43
Ok, I see. Thanks for your kind help.
Joshua
2009-12-18 16:12:22
This doesn't seem to work. I'm using this with an Outline View but it should still work, Right? Because NSOutlineView is a Sub-Class of NSTableView?
Joshua
2009-12-18 16:21:56
This should still work. Make sure that your outlets are connected and make sure your calling this method after the view has been initialized. Hence, do not call this in an "init" method, use - (void)awakeFromNib.
Brad Goss
2009-12-18 16:46:12
Odd, It doesn't work in -(void)awakeFromNib but it does work as an IBAction linked to a button.
Joshua
2009-12-18 17:49:10
is the view loaded from a nib? or are you programmatically creating it?
Brad Goss
2009-12-18 18:08:42
The View is a window in the nib.
Joshua
2009-12-18 18:28:35
how is the method that invokes the code provided called? If invoking the code by a user action works then you must be calling it when the view is not yet loaded from the nib. The controller that invokes the code may not be loaded from a nib, so awakeFromNib may never be called.
Brad Goss
2009-12-18 21:17:37
The controller is an object in the nib. Could it be that the Outline View is not yet populated when awakeFromNib is called?
Joshua
2009-12-19 07:51:08
Yes. Very possible.
Brad Goss
2009-12-19 15:48:01
When else/In what other method could the Outline View be populated?
Joshua
2009-12-19 16:29:07
If it makes any difference I am trying to do this with the NewsReader example project. http://developer.apple.com/mac/library/samplecode/NewsReader/index.html
Joshua
2009-12-19 16:42:16
Don't worry I've figured it out!
Joshua
2009-12-19 16:47:54