• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSButtonCell binds only readonly; Non-bool bindings OK.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSButtonCell binds only readonly; Non-bool bindings OK.


  • Subject: Re: NSButtonCell binds only readonly; Non-bool bindings OK.
  • From: Jerry Krinock <email@hidden>
  • Date: Sat, 25 Apr 2009 14:15:38 -0700


On 2009 Apr 23, at 11:27, Kyle Sluder wrote:

Have you instead tried just dynamically unbinding and
rebinding the columns in response to your user input?

I have now. Thanks, Kyle! -- It took me less than 15 minutes to add that 10 lines of code and trash a whole file of crap I had written. I'm a fan of -unbind: now.


Then, with less code to read, I was able to find the ^real^ problem. Documentation of -[NSTableColumn dataCellForRow:], states that "NSTableView always calls this method", implying that -dataCell is not invoked directly. [1] So I'd never bothered to implement -dataCell or care about what data cell I had set for a table column in Interface Builder, because it was supposed to be ignored. But in fact, when the 'value' binding on a table column is bound, Cocoa invokes -dataCell directly, quite regularly, bypassing -dataCellForRow:.

Of course, this documentation was written long before Cocoa Bindings was introduced with Panther, and one can easily imagine how this disparate effect would have gone unnoticed when documentation was updated for Panther.

My app works now that I replaced the old-style -dataCellForRow: implementation [2] with a revised implementation [3].

I've also submitted one of those "It wasn't helpful" thingeys on the outdated documentation.

Jerry


[1] From the Documentation:

http://developer.apple.com/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTableColumn_Class/Reference/Reference.html#/ /apple_ref/occ/instm/NSTableColumn/dataCellForRow:

- (id)dataCellForRow:(NSInteger)row

"NSTableView always calls this method. By default, this method just calls dataCell. Subclassers can override if they need to potentially use different cells for different rows. Subclasses should expect this method to be invoked with row equal to –1 in cases where no actual row is involved but the table view needs to get some generic cell info."


[2] Old-Style -dataCellForRow: implementation

- (id)dataCellForRow:(int)iRow {
   if (iRow < 0)  {
        // OS wants generic cell information
        return ([self dataCell]) ;
    }

    // Assign appropriate cell
    NSCell* cell = ..... ;

    // Further modify cell if desired based on -itemAtRow:
    ....

    // return cell ;
}	


[3] Updated Implementations, compatible with Cocoa Bindings:

- (id)dataCell {
    // Note: NSNotFound is a very large positive number.
    return [self dataCellForRow:NSNotFound] ;
}

- (id)dataCellForRow:(int)iRow {
    if (iRow < 0)  {
        // OS wants generic cell information
        return ([self dataCell]) ;
    }

    // Assign appropriate cell
    NSCell* cell = ..... ;

    if (iRow < NSNotFound) {
        // Further modify cell if desired based on -itemAtRow:
        ...
    }

    return cell ;
}

_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: NSButtonCell binds only readonly; Non-bool bindings OK.
      • From: Kyle Sluder <email@hidden>
References: 
 >NSButtonCell binds only readonly; Non-bool bindings OK. (From: Jerry Krinock <email@hidden>)
 >Re: NSButtonCell binds only readonly; Non-bool bindings OK. (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Trying to get flagsChanged: to work
  • Next by Date: Re: Clicking through a NSView with CALayers
  • Previous by thread: Re: NSButtonCell binds only readonly; Non-bool bindings OK.
  • Next by thread: Re: NSButtonCell binds only readonly; Non-bool bindings OK.
  • Index(es):
    • Date
    • Thread