Comments on: Data for a custom cell in a NSTableView http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/ hot bits and bytes Sun, 18 May 2008 10:49:48 +0000 http://wordpress.org/?v=2.2.1 By: martin http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-7989 martin Thu, 29 Nov 2007 13:02:30 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-7989 <p>If you mean the website design it's just an adoption of the kubrick design I done for myself.</p> If you mean the website design it’s just an adoption of the kubrick design I done for myself.

]]>
By: naisioxerloro http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-7987 naisioxerloro Thu, 29 Nov 2007 02:35:06 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-7987 <p>Hi. Good design, who make it?</p> Hi.
Good design, who make it?

]]>
By: Mike http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-2084 Mike Mon, 30 Apr 2007 14:54:20 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-2084 <p>Is there sample source code of this in action anywhere? I learn best by tearing it apartb and seeing what makes it tick. ;)</p> Is there sample source code of this in action anywhere? I learn best by tearing it apartb and seeing what makes it tick. ;)

]]>
By: Mint http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-1758 Mint Mon, 23 Apr 2007 18:16:06 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-1758 <p>I did answer to my own question:</p> <p>I have subclassed NSTableColumn and NSTextFielCell (my NSTextFieldCell display on line of text and 2 icons using binding and coredata)</p> <p>in NSTableColumn i subclassed: dataCellForRow like this:</p> <p>-(id)dataCellForRow:(int)row { OOCell *cell = [self dataCell]; if(row >= 0) { [cell setFolderImageName:[folderImageName objectAtIndex:row]]; if(badgeImageCount!=nil) {</p> <pre><code> [cell setBadgeImageCount:[[badgeImageCount objectAtIndex:row]intValue]]; } else { [cell setBadgeImageCount:0]; } } </code></pre> <p>return cell; }</p> <p>In fact the tableColumn use the arrangedObjects array to send data to the cell as i suppose the cells are displayed in the same order as the arrangedObjects array</p> <p>I also implemented </p> <ul> <li>(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context in the tableColumn</li> </ul> <p>Graphics Bindings and Clock Control from mmalc web page are very good example on what to do to subclass a NSCell and use binding</p> <p>I hope i will have the time to post my solution in a blog in sometimes</p> I did answer to my own question:

I have subclassed NSTableColumn and NSTextFielCell
(my NSTextFieldCell display on line of text and 2 icons using binding and coredata)

in NSTableColumn i subclassed:
dataCellForRow like this:

-(id)dataCellForRow:(int)row
{
OOCell *cell = [self dataCell];
if(row >= 0)
{
[cell setFolderImageName:[folderImageName objectAtIndex:row]];
if(badgeImageCount!=nil)
{

 [cell setBadgeImageCount:[[badgeImageCount objectAtIndex:row]intValue]];

 }
 else
 {
 [cell setBadgeImageCount:0];
 }
 }

return cell;
}

In fact the tableColumn use the arrangedObjects array to send data to the cell as i suppose the cells are displayed in the same order as the arrangedObjects array

I also implemented

  • (void)observeValueForKeyPath:(NSString *)keyPath
    ofObject:(id)object
    change:(NSDictionary *)change
    context:(void *)context
    in the tableColumn

Graphics Bindings and Clock Control from mmalc web page are very good example on what to do to subclass a NSCell and use binding

I hope i will have the time to post my solution in a blog in sometimes

]]>
By: Mint http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-1596 Mint Mon, 09 Apr 2007 09:55:28 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-1596 <p>Hello</p> <p>I am trying to develop a custom NSTextfieldCell to display in a tableview, the cell will be used to show one string and two icons.</p> <p>I bind my tablecolumn to the arrangedObjects.key keypath.</p> <p>I allways get the same problem: the cell receive the array (of icon name) of the arranged objects and not a single value. I am unable to display my cell</p> <p>I believe my custom cell (and custom tablecolumn) are KVO compliant.</p> <p>I did have a look at mmalc samples, and also RMTextFieldCell and i still don't succeed to get the value for each cell.</p> <p>Can someone have an answer to this problem. I would like to avoid to have to use the old way to populate a tableview. Thanks !!</p> Hello

I am trying to develop a custom NSTextfieldCell to display in a tableview, the cell will be used to show one string and two icons.

I bind my tablecolumn to the arrangedObjects.key keypath.

I allways get the same problem: the cell receive the array (of icon name) of the arranged objects and not a single value. I am unable to display my cell

I believe my custom cell (and custom tablecolumn) are KVO compliant.

I did have a look at mmalc samples, and also RMTextFieldCell and i still don’t succeed to get the value for each cell.

Can someone have an answer to this problem. I would like to avoid to have to use the old way to populate a tableview.
Thanks !!

]]>
By: martin http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-1277 martin Mon, 26 Mar 2007 19:02:19 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-1277 <p>Hello Stéphane,</p> <p>That sounds very promising and I gave it a try but unfortunatley I couldn't make it work. The problem is that for each line of the table I have a specific object. In order to get the right data I have to create a binding to these objects. So I would have to rebind during the loop that fills the table. The only thing I could imagine is to bind to the cell's object-value and to rebind each time the cell value is being changed.</p> <p>Am I missing something?</p> Hello Stéphane,

That sounds very promising and I gave it a try but unfortunatley I couldn’t make it work.
The problem is that for each line of the table I have a specific object. In order to get the right data I have to create a binding to these objects.
So I would have to rebind during the loop that fills the table.
The only thing I could imagine is to bind to the cell’s object-value and to rebind each time the cell value is being changed.

Am I missing something?

]]>
By: Stéphane http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-1223 Stéphane Sat, 24 Mar 2007 18:10:34 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-1223 <p>Bindings are much more flexible than you think. If your cell has, say, 3 ivars, myImage, myMainText and mySubtext values. You can simply do the following:</p> <p>NSTableColumn *aCol;</p> <p>[[aCol dataCell] bind:@"myImage" toObject:... withKeyPath:@"data.image" options:...]; [[aCol dataCell] bind:@"myMainText" toObject:... withKeyPath:@"data.mainText" options:...]; [[aCol dataCell] bind:@"mySubtext" toObject:... withKeyPath:@"data.subText" options:...];</p> <p>myMainText could be the cell's objectValue, to avoid adding that ivar. In your cell subclass, your setters need to tell the controlView to refresh itself whenever new value is different from old one. Look here for such an example: http://wonder.cvs.sourceforge.net/wonder/Wonder/Utilities/RuleModeler/ - see RMTextFieldCell, which is used as a tableView data cell that highlights some parts of its string value according to a search filter.</p> Bindings are much more flexible than you think.
If your cell has, say, 3 ivars, myImage, myMainText and mySubtext values. You can simply do the following:

NSTableColumn *aCol;

[[aCol dataCell] bind:@”myImage” toObject:… withKeyPath:@”data.image” options:…];
[[aCol dataCell] bind:@”myMainText” toObject:… withKeyPath:@”data.mainText” options:…];
[[aCol dataCell] bind:@”mySubtext” toObject:… withKeyPath:@”data.subText” options:…];

myMainText could be the cell’s objectValue, to avoid adding that ivar.
In your cell subclass, your setters need to tell the controlView to refresh itself whenever new value is different from old one.
Look here for such an example: http://wonder.cvs.sourceforge.net/wonder/Wonder/Utilities/RuleModeler/ - see RMTextFieldCell, which is used as a tableView data cell that highlights some parts of its string value according to a search filter.

]]>
By: martin http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-982 martin Mon, 26 Feb 2007 20:36:51 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-982 <p>What a great idea! Never thought about using key path for this. Great!</p> <p>In my particular case I'm doing more stuff in the delegate (adjust colors....) and therefore I'm also sending the cell itself to the delegate. So in this case it would would not work with the key path. </p> <p>I think the difference is similar to the bindings vs. datasource stuff. Bindings are great and easy to use, but you could get to the limits and are stuck. Datasources are flexible but you have to code a lot.</p> <p>Your idea reminds me to not forget the power of the dynamics of Objective-C. I must get out this (static) Java stuff from my head.</p> What a great idea! Never thought about using key path for this. Great!

In my particular case I’m doing more stuff in the delegate (adjust colors….) and therefore I’m also sending the cell itself to the delegate.
So in this case it would would not work with the key path.

I think the difference is similar to the bindings vs. datasource stuff. Bindings are great and easy to use, but you could get to the limits and are stuck. Datasources are flexible but you have to code a lot.

Your idea reminds me to not forget the power of the dynamics of Objective-C. I must get out this (static) Java stuff from my head.

]]>
By: Markus http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-981 Markus Mon, 26 Feb 2007 20:13:23 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-981 <p>Regarding solution 2: we agree that the custom cell must know which kind of data it can expect (e.g. two strings and one image) - the problem is how to get it from the bound object. Why not parametrize the custom cell with the keys of data-object? Something like this (in the custom cell's class):</p> <ul> <li>(id)initWithPathsForMainText:(NSString *)p1 subText:(NSString *)p2 image:(NSString *)p3</li> </ul> <p>So you can reuse your custom cell with nearly every kind of data-object (at least with such ones hat can provide an image and two strings)...</p> Regarding solution 2:
we agree that the custom cell must know which kind of data it can expect (e.g. two strings and one image) - the problem is how to get it from the bound object.
Why not parametrize the custom cell with the keys of data-object?
Something like this (in the custom cell’s class):

  • (id)initWithPathsForMainText:(NSString *)p1 subText:(NSString *)p2 image:(NSString *)p3

So you can reuse your custom cell with nearly every kind of data-object (at least with such ones hat can provide an image and two strings)…

]]>
By: Nick Brawn’s Weblog · The interface refactoring continues http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-505 Nick Brawn’s Weblog · The interface refactoring continues Tue, 12 Dec 2006 04:15:52 +0000 http://www.martinkahr.com/2006/11/04/data-for-a-custom-cell-in-a-nstableview/#comment-505 <p>[...] Data for a custom NSCell in NSTableView [...]</p> […] Data for a custom NSCell in NSTableView […]

]]>