Re: Creating a NSTableView cell the "iPhone way"
Re: Creating a NSTableView cell the "iPhone way"
- Subject: Re: Creating a NSTableView cell the "iPhone way"
- From: Alastair Houghton <email@hidden>
- Date: Thu, 10 Jun 2010 10:12:38 +0100
On 10 Jun 2010, at 08:37, Gustavo Pizano wrote:
> Well I have created custom table view cells in the way that I create my subclass of NSCell, and then in the -(void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView method I make the drawing.
>
> now i wonder if I can do it the iPHone way, create a xib with a NSCell view, place the other views I need in the cell, and in the delegate of the NSTableView method. - (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumnrow:(NSInteger)row return an instance of my custom cell .
No. Or rather, you *could*, but you'd have to make a special NSCell that loaded the xib file, added all the views as subviews of the table view (in appropriate places) and conspired somehow to manage the set of views so that you didn't just end up adding/creating more and more views as the user scrolls around.
The root of the problem is that NSCell is not a view, and moreover the table view may use the same cell over and over when drawing its rows.
> Now what implications will this have if I using core data?, I will have an NSArryaController as the dataSource for the table view, so my guess is that when returning the cell instance, I must get the object from the arrangedObject array of the NSArryaController at the given row.
>
> am I right, wrong? what else am I missing?
Wrong. NSCell is not a view. There is not one NSCell per table "cell"; generally speaking, NSCells are re-used, and so the data is set before drawing using -setObjectValue: or similar.
If you do need views in a table view (e.g. because you want a progress indicator, or you want to do mouse tracking or something), there are plenty of examples:
<http://www.google.co.uk/search?hl=en&source=hp&q=nsview+in+nstableview>
For many applications, though, this is unnecessary and you should just use appropriate NSCell instances; if the provided NSCells and NSFormatters aren't sufficient for you, it's usually possible to write a custom NSCell that draws whatever it is you need.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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