objective-cmacoscocoansbrowser

How to find user clicked on any row in NSBrowser?


In my Browser implementation to select default rows I have used the following code.

[browser setTarget:self];
[browser setAction:@selector(singleClickOnBrowser:)];
[browser sendActionOn:NSLeftMouseDown];
[browser selectRow:0 inColumn:0];
[browser sendAction];

Is there any way to differentiate user click and the rows selected for the first time to select default rows?


Solution

  • I did not find any API to differentiate user click and selecting the rows and columns from code. To achieve this I declared a BOOL variable to keep track of user clicks.

    Following Code I changed the BOOL variable in Code.

    self.userClickedOnRow = NO;
            [self.browser selectRow:0 inColumn:0];
        [self.browser sendAction];
            self.userClickedOnRow = YES;
    

    Implemented the following delegate

     - (void)browser:(NSBrowser *)browser didChangeLastColumn:(NSInteger)oldLastColumn toColumn:(NSInteger)column
        {
    
            if(!self.userClickedOnRow)
            {
                NSLog(@"Programatic selection");
            }
            if (self.userClickedOnRow)  
            {
                self.userClickedOnRow = NO;
                // User Clicked on the browser,Do the required actions and set the variable again.
                self.userClickedOnRow = YES;
    
    }
    }