Get selectedItem (and items) in NSOutlineView

  • Hello,
    I need to get the selected item of an NSOutlineView with a custom datasource.
    I've tried to use:

    NSLog(@"Selected: %@",[[self itemAtRow:[self selectedRow]] getSubject]);

    But it returns the previous selected item! For example if I select A
    it returns null, then if I select B it return A (the prev).
    Why?
  • I'd guess selectedRow is 0-based while itemAtRow isnt.

    Am Oct 28, 2006 um 6:27 PM schrieb malcom:

    > Hello,
    > I need to get the selected item of an NSOutlineView with a custom
    > datasource.
    > I've tried to use:
    >
    > NSLog(@"Selected: %@",[[self itemAtRow:[self selectedRow]]
    > getSubject]);
    >
    > But it returns the previous selected item! For example if I select A
    > it returns null, then if I select B it return A (the prev).
    > Why?
    > _______________________________________________
    > Do not post admin requests to the list. They will be ignored.
    > Cocoa-dev mailing list      (<Cocoa-dev...>)
    > Help/Unsubscribe/Update your Subscription:
    > http://lists.apple.com/mailman/options/cocoa-dev/<dominik...>
    >
    > This email sent to <dominik...>
    >
  • Mmmm tried to +1 but this not solve the problem.
    In fact it's not an index problem.
    Suppose to have a just loaded table.
    Now you click item A ---> the selection method return <NULL>
    Now you click another item B (wherever you want...) ---> the selection
    method return A
    ....item C ---> the seleciton return B

    in fact it return the previous selected item and not the current. It's
    datasource table.
    The method is:
    - (id)selectedItem { return [self itemAtRow: [self selectedRow]]; }
  • On Oct 28, 2006, at 5:27 PM, malcom wrote:

    > Hello,
    > I need to get the selected item of an NSOutlineView with a custom
    > datasource.
    > I've tried to use:
    >
    > NSLog(@"Selected: %@",[[self itemAtRow:[self selectedRow]]
    > getSubject]);
    >
    > But it returns the previous selected item! For example if I select A
    > it returns null, then if I select B it return A (the prev).
    > Why?

    My guess is that you're calling it before the NSOutlineView has
    actually changed its selection.  Which event are you responding to to
    log this information?

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today