Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Thanks for your question, I also will be triggering an action from a button on a NSTableView. Your question helped to put me on the correct path.</p> <p>First to address the your solution to finding which row number my NSTableView is on. I was able to find it without knowing the button, in my custom NSTableView I installed the following as a first attempt: </p> <pre><code>- (NSInteger)myRowNumber { return [(NSTableView*)self.superview.superview rowForView:self]; } </code></pre> <p>this works fine, however it is less than robust. It only works if you already know specifically how deep you are in the view hierarchy. A more robust and universal solution is:</p> <pre><code>- (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]; } </code></pre> <p>this not only works at the NSTableView level, but works with anything installed at any level above it, no matter how complex the view hierarchy.</p> <p>As to the unanswered part of your question, I established an IBOutlet in my class and using interface builder tied if to my files owner (in my case my document class). Once I had a reference to the class I was sending my message to, and the row number, I call the function. In my case the call required that I pass the row number it originates from.</p> <pre><code>[self.myDoc doSomethingToRow:self.myRowNumber]; </code></pre> <p>I tested this and it works at various levels of the view hierarchy above NSTableView. And it functions without having to have the row selected first (which appears to be assumed in Apples documentation).</p> <p>Regards, George Lawrence Storm, Maltby, Washington, USA</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload