|
|
How to find selected item in NSOutlineView?
|
|
|
|
Junior Member
Join Date: May 2002
Location: Okinawa, Japan (Kadena AB)
Status:
Offline
|
|
Maybe I'm just missing something obvious here, but is there an easy way to find the currently selected item in an OutlineView? Before someone gets all smart and says 'Yea, just use [outlineView selectedRow];.' Let me say that that doesn't give me the desired results. In my outline view, there are several expandable items within expandable items. So finding the currently selected item is kind of a pain. I haven't found a way to do it yet, and Apple's DragNDropOutlineView is confusing as all heck (I hate their Macro usage, makes everything confusing -- especially for newbies). Let me explain a little more. When this method fires:
- (BOOL)selectionShouldChangeInOutlineView NSOutlin eView *)outlineView
I need to be able to find what item is selected, and then save some information based on that item.
Anyone know of a way to do this? I've been trying to figure it out for a few months now and I'm finaly at the stage of begging people to help me figure this out.
Thanks in advance,
- Daniel
|
Daniel Howard | Mac OS X (10.2.2) | TiBook867 /\ iSub w/ Soundsticks /\ iPod
www.midnite-liteman.com | ideaSpiral 1.5.3 / DVD Rack 1.0.2
|
|
|
|
|
|
|
|
Forum Regular
Join Date: Sep 2000
Location: UK
Status:
Offline
|
|
Code:
- (id)itemAtRow:(int)row
Just pass in the selectedRow, and you're done!
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: May 2002
Location: Okinawa, Japan (Kadena AB)
Status:
Offline
|
|
OMG, you know that makes complete sense. I've been looking at itemForRow for sometime now, but it never clicked as to how it would work. It just clicked! Thanks!
Cheers,
- Daniel
|
Daniel Howard | Mac OS X (10.2.2) | TiBook867 /\ iSub w/ Soundsticks /\ iPod
www.midnite-liteman.com | ideaSpiral 1.5.3 / DVD Rack 1.0.2
|
|
|
|
|
|
|
|
Junior Member
Join Date: May 2002
Location: Okinawa, Japan (Kadena AB)
Status:
Offline
|
|
Ok, I lied... I tested it out and it didn't work. *grins*
This is my code. Maybe you can see something that is making it not work?
//This method is called right before a change is made in the outlineView.
- (BOOL)selectionShouldChangeInOutlineView NSOutlin eView *)outlineView
{
NSData *data = [textField RTFDFromRange:NSMakeRange(0, [[textField string] length])];
[[noteData objectAtIndex:[noteBoxView itemAtRow:[noteBoxView selectedRow]]] setObject:data forKey:@"Notes"];
NSLog(@"...selectionShouldChangeInOutlineView");
}
Thanks in advance,
- Daniel
|
Daniel Howard | Mac OS X (10.2.2) | TiBook867 /\ iSub w/ Soundsticks /\ iPod
www.midnite-liteman.com | ideaSpiral 1.5.3 / DVD Rack 1.0.2
|
|
|
|
|
|
|
|
Clinically Insane
Join Date: Oct 2001
Location: San Diego, CA, USA
Status:
Offline
|
|
It looks like objectAtIndex: should take an int, but you're giving it an id (from itemAtRow:).
|
Chuck
___
"Instead of either 'multi-talented' or 'multitalented' use 'bisexual'."
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Jan 2003
Location: NYC
Status:
Offline
|
|
yeah, objectAtIndex needs an int, and selectedRow returns an int, so you jsut need to do...
[noteData objectAtIndex:[noteBoxView selectedRow]]
|
|
|
|
|
|
|
|
|
Registered User
Join Date: Sep 2001
Status:
Offline
|
|
Yup, just change it to [[noteBoxView itemAtRow:[noteBoxView selectedRow]] setObject:data forKey:@"Notes"];
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: May 2002
Location: Okinawa, Japan (Kadena AB)
Status:
Offline
|
|
Originally posted by Jan Van Boghout:
Yup, just change it to [[noteBoxView itemAtRow:[noteBoxView selectedRow]] setObject:data forKey:@"Notes"];
Thanks for the reply, but I do have one question. If I use the above code, how would my array 'noteData' know to add the desired data forKey:@"Notes"? I'm a bit confused...
Thanks,
- Daniel
|
Daniel Howard | Mac OS X (10.2.2) | TiBook867 /\ iSub w/ Soundsticks /\ iPod
www.midnite-liteman.com | ideaSpiral 1.5.3 / DVD Rack 1.0.2
|
|
|
|
|
|
|
|
Registered User
Join Date: Sep 2001
Status:
Offline
|
|
Originally posted by DSHwrd:
Thanks for the reply, but I do have one question. If I use the above code, how would my array 'noteData' know to add the desired data forKey:@"Notes"? I'm a bit confused...
Thanks,
- Daniel
I assume the object that the selected item represents listens to setObject:forKey: ?
For example, in my app I have a collection of CSSObject classes to which I can apply some values such as setName: , setSource: etc. Some of the objects can be groups etc etc. Getting the selected item, I can just call setName: after an edit for example, without having to search what item is clicked myself.
Hmm� while writing this I am confused How does your underlying model for the outline view work? A main array that contains normal objects and other arrays? Because setObject:forKey is normally a method for dictionaries, unless you make your own version for a custom class.
|
|
|
|
|
|
|
|
|
Junior Member
Join Date: May 2002
Location: Okinawa, Japan (Kadena AB)
Status:
Offline
|
|
Yes, it is a dictionary. Heh. I figured it'd be easier to do it that way. I think I'm kind of understanding what you're saying. Just use the datasource to add my information too. (It makes sense in my head... heh) I'll give it a shot and post back here on whether or not it works. I'm hopeful!
Thanks,
- Daniel
|
Daniel Howard | Mac OS X (10.2.2) | TiBook867 /\ iSub w/ Soundsticks /\ iPod
www.midnite-liteman.com | ideaSpiral 1.5.3 / DVD Rack 1.0.2
|
|
|
|
|
|
|
|
Junior Member
Join Date: May 2002
Location: Okinawa, Japan (Kadena AB)
Status:
Offline
|
|
yay! I got it to work. Now I need to work on Drag and Drop... Yippie... Oh the joy.
Thanks for all the help,
- Daniel
|
Daniel Howard | Mac OS X (10.2.2) | TiBook867 /\ iSub w/ Soundsticks /\ iPod
www.midnite-liteman.com | ideaSpiral 1.5.3 / DVD Rack 1.0.2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|