On 20/11/2010, at 1:17 AM, Vincent Habchi wrote:

> Hi there,
> 
> I'm beginning to figure out something but I'd like to have some (even terse) 
> comments.
> 
> I have created a custom subclass of NSCell that duplicates the behavior of a 
> NSColorWell: It draws a small colored rectangle inside of its frame, and 
> responds to a click by opening the shared color panel.
> 
> However, I would have liked to set my custom cell as the target of the shared 
> color panel action, in order to refresh its color as the user moves inside 
> the color panel. It failed. So the question is: is there a way to do this, or 
> is it mandatory to connect the action to the NSControl object responsible for 
> the cell (in my case, a table view).


1. Playing nice with the color panel requires a little care, because it's 
shared by not only any color wells in your app, but by any responders that 
implement -changeColor:

2. A table column only has one cell, reused as needed to draw each row. So 
connecting the cell directly to the panel is a bad idea - all the colours in 
all rows will change at once.

3. Use MVC. If a property of your data model is a colour, then your controller 
can set this from the color panel via -changeColor: on a first responder 
(tableview, most likely) and some logic you'll need to implement to establish 
which row is selected for colour input. Once the property is set, you refresh 
the table as usual and the cell will display the colour for the appropriate row.

4. Getting it exactly right is not easy.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to