Re: Custom tableView cell by subclassing NSCell

2009-05-06 Thread Corbin Dunn


On May 6, 2009, at 3:50 PM, Malayil George wrote:


Thanks Joar. Turns out you were right...it wasn't really because of  
the
retain/copy semantics in my property declaration. Changing the  
variable name
to myImage and the setter/getters accordingly has taken care of the  
issue

and it works fine.



Based on your original message, it appears you were not implementing  
copyWithZone. If changing the getters/setters fixed the problem, then  
it is probably due to over-retaining something, and causing a leak.


If you were getting a crash when clicking on cells, it was (more than  
likely) because of a wrongly implemented copyWithZone:.


corbin


___

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


Re: Custom tableView cell by subclassing NSCell

2009-05-06 Thread Malayil George
Thanks Joar. Turns out you were right...it wasn't really because of the
retain/copy semantics in my property declaration. Changing the variable name
to myImage and the setter/getters accordingly has taken care of the issue
and it works fine.

George

On Tue, May 5, 2009 at 9:23 PM, Joar Wingfors  wrote:

>
> On 5 maj 2009, at 17.41, Malayil George wrote:
>
>  The modification that I have made is that in my subclass of NSCell
>>
>
>
> A couple of points:
>
> * NSCell already have an image property. Why are you adding an additional
> image property? If you're adding an additional image property, you should
> give it - and its backing ivar - distinct names.
>
> * When creating a custom cell to use in table views you need to implement
> proper support for the NSCopying protocol:
>
><
> http://developer.apple.com/documentation/Cocoa/Conceptual/ControlCell/Tasks/SubclassingNSCell.html
> >
><
> http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmImplementCopy.html
> >
>
> This is a bit tricky for NSCell, since it implements copy using
> NSCopyObject. The referenced documentation should provide you with the info
> you need though.
>
> j o a r
>
>
>
___

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


Re: Custom tableView cell by subclassing NSCell

2009-05-05 Thread Joar Wingfors


On 5 maj 2009, at 17.41, Malayil George wrote:


The modification that I have made is that in my subclass of NSCell



A couple of points:

* NSCell already have an image property. Why are you adding an  
additional image property? If you're adding an additional image  
property, you should give it - and its backing ivar - distinct names.


* When creating a custom cell to use in table views you need to  
implement proper support for the NSCopying protocol:


	
	


This is a bit tricky for NSCell, since it implements copy using  
NSCopyObject. The referenced documentation should provide you with the  
info you need though.


j o a r


___

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


Re: Custom tableView cell by subclassing NSCell

2009-05-05 Thread Malayil George
Interestingly changing the property type from copy as I had it to
retain @property
(retain) NSImage *image;
seems to have fixed the problem

   Not entirely sure why tho. I would imagine that with copy, my cell would
be getting a copy of the image with a retain count of 1. When dealloced it
goes to 0. With retain, it should just be incrementing and decrementing the
retain count for my original image object.

George


On Tue, May 5, 2009 at 8:48 PM, Malayil George  wrote:

> just found
> http://developer.apple.com/samplecode/ImageBackground/listing3.html after
> posting this...going through it to see if I can figure  it out :-)
>
>
> On Tue, May 5, 2009 at 8:41 PM, Malayil George  wrote:
>
>> Hi,   I'm trying to expand on "Styling an NSTableView" at katidev.com in
>> a test app of mine. The modification that I have made is that in my subclass
>> of NSCell, I have included a new NSImage data element
>>
>> @interface CustomCell : NSCell {
>>
>> NSImage *image;
>>
>> }
>>
>> @end
>>
>>In my appController, I set the tableView to use this cell
>>
>> CustomCell *cell = [[CustomCell alloc] init];
>>
>> [[tableView tableColumnWithIdentifier:@"Cities"] setDataCell:cell];
>>
>> [cell release];
>>
>>
>> and I set the image for the cell in my implementation of
>>
>>
>>  -(void) tableView:(NSTableView*) aTableView
>>
>>   willDisplayCell:(id) aCell
>>
>>forTableColumn:(NSTableColumn *) aTableColumn
>>
>>   row:(int) rowIndex
>>
>>
>> When I run the program, it displays the image fine. However, when I click
>> on the table row's it crashes. I see that it is deallocing my cell (via an
>> NSLog()) in the CustomCell's dealloc method. So, I guess it is crashing as
>> the cell is being dealloced, and then in willDisplayCell, it is trying to
>> set the image.
>>
>>
>> I tried setting aCell in the willDisplayCell method to a newly allocated
>> instance of CustomCell and also tried doing the setDataCell method with that
>> new instance. It still crashes...should I be initializing the cell someplace
>> else?
>>
>> Reading the documentation it seems that a single cell is used for all rows
>> of the table Column. So, I'm guessing when the application launches it is
>> using my initialized customCell for all rows and displaying it without
>> deallocing it. However, when I click a row, it deallocs and tries to do the
>> same again.
>>
>> Any pointers on if and when I should be giving the tableView a newly
>> allocated instance of the cell? Thanks
>>
>>
>>
>> George
>>
>>
>>
>
___

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


Re: Custom tableView cell by subclassing NSCell

2009-05-05 Thread Malayil George
just found
http://developer.apple.com/samplecode/ImageBackground/listing3.html after
posting this...going through it to see if I can figure  it out :-)

On Tue, May 5, 2009 at 8:41 PM, Malayil George  wrote:

> Hi,   I'm trying to expand on "Styling an NSTableView" at katidev.com in a
> test app of mine. The modification that I have made is that in my subclass
> of NSCell, I have included a new NSImage data element
>
> @interface CustomCell : NSCell {
>
> NSImage *image;
>
> }
>
> @end
>
>In my appController, I set the tableView to use this cell
>
> CustomCell *cell = [[CustomCell alloc] init];
>
> [[tableView tableColumnWithIdentifier:@"Cities"] setDataCell:cell];
>
> [cell release];
>
>
> and I set the image for the cell in my implementation of
>
>
>  -(void) tableView:(NSTableView*) aTableView
>
>   willDisplayCell:(id) aCell
>
>forTableColumn:(NSTableColumn *) aTableColumn
>
>   row:(int) rowIndex
>
>
> When I run the program, it displays the image fine. However, when I click
> on the table row's it crashes. I see that it is deallocing my cell (via an
> NSLog()) in the CustomCell's dealloc method. So, I guess it is crashing as
> the cell is being dealloced, and then in willDisplayCell, it is trying to
> set the image.
>
>
> I tried setting aCell in the willDisplayCell method to a newly allocated
> instance of CustomCell and also tried doing the setDataCell method with that
> new instance. It still crashes...should I be initializing the cell someplace
> else?
>
> Reading the documentation it seems that a single cell is used for all rows
> of the table Column. So, I'm guessing when the application launches it is
> using my initialized customCell for all rows and displaying it without
> deallocing it. However, when I click a row, it deallocs and tries to do the
> same again.
>
> Any pointers on if and when I should be giving the tableView a newly
> allocated instance of the cell? Thanks
>
>
>
> George
>
>
>
___

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