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: Gustavo Pizano <email@hidden>
- Date: Thu, 10 Jun 2010 11:49:15 +0200
Alastair Hi.
Yes, sorry I didn't think properly when typing, NSCell is not a view, and unfortunately Cocoa doesn't offer the option as UIKit to drag in IB a ("NSTableCell"), and just put all the controls there, then set the Identifier to reuse, configure the cell and return the cell, in the delegate method... :(
So checking some examples, if I want to place some view in a cell I must pass to the custom cell a weak reference of the view, then in the draWithRect method add the view to the controlView?.. interesting..
I was drawing attributed strings instead.. but now i need to support selection of that text.
I will give it a try then.
Thx
G.
On Jun 10, 2010, at 11:12 AM, Alastair Houghton wrote:
> 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