How to call an action from an NSTableCellView in an NSTableView-based view when using bindings

I am having a problem with a view-based NSTableView running on 10.8 (the goal is 10.7, but I think this is not relevant).

I use NSTableView and I get content values ​​for my custom NSTableCellView through bindings. I use obejctValue NSTableCellView to get my data.

I added a button to my cell, and I would like it to work when clicked. So far, I have only managed to activate the action in the custom subclass of NSTableCellView.

I can get the string that was pressed like this using the chain:

NSButton *myButton = (NSButton*)sender;    

NSTableView *myView = (NSTableView*)myButton.superview.superview.superview;

NSInteger rowClicked = [myView rowForView:myButton.superview];

From there, I don't know how to get to my App Delegate or controller where the action is defined.

cocoa, NSTableView, .

, ?

!

+5
3

, , .

, . , .

+2

, NSTableView. .

, NSTableView. , , NSTableView :

- (NSInteger)myRowNumber  
{  
    return [(NSTableView*)self.superview.superview rowForView:self];  
}

, . , , . :

- (NSInteger)myRowNumber  
{   
    NSTableView* tableView = nil;   
    NSView* mySuperview = self;   

    do   
    {   
        NSView* nextSuper = mySuperview.superview;   
        if (nextSuper == nil)   
        {   
            NSException *exception =   
                [NSException exceptionWithName:@"NSTableView not found."   
                    reason:[NSString stringWithFormat:@"%@ search went too deep.",   
                    NSStringFromSelector(_cmd)] userInfo:nil];   
            @throw exception;   
        }   

        if ([nextSuper isKindOfClass:[NSTableView class]])   
            tableView = (NSTableView*)nextSuper;   
        else   
            mySuperview = mySuperview.superview;   
    } while (tableView == nil);   

    return [tableView rowForView:self];   
}   

NSTableView, , , , .

, IBOutlet , ( ). , , , . , , .

[self.myDoc doSomethingToRow:self.myRowNumber];   

, NSTableView. (, , Apples).

, , , ,

+3

rowForView:

, NSTableCellView, First Responder. File Owner, .

rowForView: , , :

- (IBAction)revealInFinder:(id)sender {
    NSInteger row = [self.tableView rowForView:sender];
    ...
}

. , NSWindowController. ; , NSTableView.

. Apple TableViewPlayground: NSTableView NSOutlineView View, .

+1

All Articles