For a view in my iPhone application, I am using a subclass of the ABTableViewCell
(https://github.com/enormego/ABTableViewCell). It's a fairly simple cell, but I wanted to use this for the scrolling speed I need, because a lot of them can in the table at once.
Here is the header of the file:
@interface WHUserTableViewCell : ABTableViewCell {
NSString* Name;
NSString* DetailsText;
UIImage* UserImage;
}
@property (nonatomic, copy) NSString* Name;
@property (nonatomic, copy) NSString* DetailsText;
@property (nonatomic, copy) UIImage* UserImage;
I know that by using 'copy' on an image, I am only supporting iOS 4.2 and up, but that is something I might fix later.
I follow the way AteBits uses this cell, by creating custom set methods for the properties, like this:
- (void) setUserImage:(UIImage *) userImage
{
[UserImage release];
UserImage = [userImage copy];
[self setNeedsDisplay];
}
- (void) setName:(NSString *) name
{
[Name release];
Name = [name copy];
[self setNeedsDisplay];
}
- (void) setDetailsText:(NSString *) detailsText
{
[DetailsText release];
DetailsText = [detailsText copy];
[self setNeedsDisplay];
}
The images that are assigned to the 'UserImage' property, are coming from a Singleton class, which provides caching and downloading of the images. So that class should be the 'owner' of the images.
There is only one problem, once the cell deallocs, and I release all the properties the application crashes on the [UserImage release]
line, here's my dealloc method:
- (void)dealloc
{
[super dealloc];
[UserImage release];
[Name release];
[DetailsText release];
}
This cell uses custom drawing, just like AteBits explains in his famous blog post about this. What is the correct and fastest way to handle images for this. I would like to continue using my singleton caching/downloading class to handle images, but I don't think that is the source of the problem, since I am copying the image objects.