Search code examples
objective-ccocoansoutlineview

How to get an specific item in a NSOutLineView?


I am currently playing with the SourceView example from Apple.

As a task I wanted to change the menu at the bottom of the application into a context menu on right click. Now I have implemented a NSMenuDelegateand using the menuWillOpen method to make my adjustments in the menu.

The problem I face now is that I can not get information about the object I right clicked in the tree.

I got the index of the item but I can not get the item itself.

NSInteger *clickedRow = [myOutlineView clickedRow];

I tried this, but it does not give me anything.

ChildNode *item = [myOutlineView itemAtRow:clickedRow];

I hope someone can help me out here.

Thanks.


Solution

  • How do you determine the clickedRow?
    One thing that seems to be wrong is, that you are storing the clickedRow in an integer pointer (NSInteger*) instead of an integer.
    So itemAtRow: possibly uses an arbitrary address instead of the actual row index to lookup the item.
    Another thing is, that itemAtRow: returns an NSTreeControllerNode* and not a ChildNode* as you are assuming.
    You should use

    [[myOutlineView itemAtRow:clickedRow] representedObject];
    

    instead