• 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: Using NSCell to bold cells in a tableview
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using NSCell to bold cells in a tableview


  • Subject: Re: Using NSCell to bold cells in a tableview
  • From: Mike Ferris <email@hidden>
  • Date: Sat, 28 Dec 2002 11:10:46 -0800

-dataCellForRow: was added as a hook for subclassers of NSTableColumn in case they wanted to be able to return different cells for different rows. The default behavior is for a table column to have a single cell for all rows, so the default implementation is for that method to simply call -dataCell.

PropertyListEditor, for example, subclasses NSTableColumn and implements -dataCellForRow: to consult the table's delegate. If the delegate returns a cell, it uses that, otherwise, it uses the cell from the table column's -dataCell method. The delegate then returns a special popup cell for the value column in cases where the type is Boolean (the Yes/No popup) or where the particular row is limited to a specific set of values. (In fact, -dataCellForRow: was added to NSTableColumn by the developer of PropertyListEditor specifically to solve that problem and was made public because it was recognized as a generally useful thing.)


There are three ways you could do what you originally asked about:

- You could subclass NSTableColumn and return different cells for -dataCellForRow:
- You could implement -tableView:willDisplayCell:forTableColumn:row: in your table view delegate and set the one data cell's font appropriately each time it is used.
- You could return attributed strings from your dataSource's -tableView:objectValueForTableColumn:row: instead of a simple string and have the attributed strings be bold or not (or whatever)

Which one is right for you depends. Since the cells are always textual in your case and it is just the font changing, I would steer clear of the first possibility. -dataCellForRow: is most useful for cases like PropertyListEditor where different classes of cell (NSTextFieldCell or NSPopUpButtonCell in this case) are required for different rows.

Of the second two choices, which is right depends on whether the boldness is simply a display attribute or whether it is something intrinsic to your model. If it is not fairly intrinsic to your model then the second choice is probably best.

Mike


Begin forwarded message:

From: Ben Mackin <email@hidden>
Date: Sat Dec 28, 2002 10:29:53 AM US/Pacific
To: matt neuburg <email@hidden>
Cc: <email@hidden>
Subject: Re: Using NSCell to bold cells in a tableview

On 12/28/02 9:20 AM, "matt neuburg" <email@hidden> wrote:

Certainly, because dataCellForRow returns the very same cell (the entire
column's single dataCell), regardless of the row, and the docs are quite clear
on this. Therefore, *this* (i.e. dataCellForRow) is what you need to be
overriding if you want to change this behavior, and the docs are clear about
this too. In short, it's just a matter of RTFM for dataCellForRow.

So why would they even include this routine, if all it does is call on
dataCell? If we have to roll our own, then what is it even there for? Maybe
someone can explain this to a Cocoa newb, but I just don't get it. When
Apple goes out of the way to specify another name for a routine, but it is
just "aliased" (for lack of a better term) to another routine, why did they
do it?

Oh, and BTW, thanks for being such a great help. I already got another email
offlist saying this (in a bit of a nicer way), and a pointer in a better
direction. So thanks Matt :)

Ben
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Using NSCell to bold cells in a tableview (From: Ben Mackin <email@hidden>)

  • Prev by Date: Re: Preference file for all the users
  • Next by Date: Re: writing & reading a file in Cocoa
  • Previous by thread: Re: Using NSCell to bold cells in a tableview
  • Next by thread: Re: Using NSCell to bold cells in a tableview
  • Index(es):
    • Date
    • Thread