NSBrowser deselection problem

  • Hi,
    I am having a problem with deselecting a cell in an NSBrowser. In my
    NSBrowserCell subclass I have implemented a fix recommended by Corbin
    Dunn so that the browser:willDisplayCell:atRow:column: gets called
    before drawing so the representedObject of the cell is set properly.
    Here is the code for reference:

    - (void)drawInteriorWithFrame:(NSRect)cellFrame inView:(NSView
    *)controlView {
    if (![self isLoaded])
      NSMatrix *matrix = (NSMatrix *)controlView;
      NSBrowser *browser = [matrix browser];
      int row = 0, col = [browser columnOfMatrix:matrix];
      for (row = 0; row < [matrix numberOfRows]; row++)
      NSCell *cell = [matrix cellAtRow:row column:0];
      if (cell == self)
      [[browser delegate] browser:browser willDisplayCell:self atRow:row
      [self setLoaded:YES];
    // do the drawing

    What I am seeing at this stage is that when I deselect a cell using
    the command key and clicking it, I see the cell deselect and then
    reselect itself. When I release the mouse I get the target/action
    method, but it contains the selected cell that really should have been

    If I comment out the if (![self isLoaded]) and let the cell call the
    browser:willDisplayCell:atRow:column: delegate method everytime it is
    about to draw itself, I can see that the when I perform the
    deselection, that the browser:willDisplayCell:atRow:column: is called
    twice - the first time the [browser selectedCells] is nil which is
    correct, but then it calls it again, this time with the cell being
    selected. When I release the mouse button I then get the target/action
    method being invoked. The only place where I set a selection on the
    browser is never being called during this sequence of events so I am
    led to believe that this may be a bug in NSBrowser or the work around
    for the NSBrowserCell subclass drawing problem isn't quite right.

    Any information or pointers in the right direction are greatly

previous month december 2007 next month
          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
Go to today