I have a custom cell for my table view which I have designed using interface builder. In its .m file I have some code like this to fetch the xib from the bundle for the custom cell.
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"SubItemsCustomCell" owner:self options:nil];
self = [nibArray objectAtIndex:0]; }
return self;
}
Then when I use this cell in my cellForRowAtIndexPath method and pass it an autorelease message
if (!cellForSubItems) {
cellForSubItems = [[[SubItemsCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SubItemCell"] autorelease];
}
it crashes when i scroll the tableView giving a message,
-[SubItemsCustomCell release]: message sent to deallocated instance 0xed198b0
It never crashed when I made a custom cell using code, but it does here, why is it so??
Also when I dont autorelease it, it runs absolutely fine, but obviously it will have memory leaks.
Kindly Help me out with this one. Thanks In Advance.
EDIT: I am not using ARC.
try my bellow code for add cell in
UITableViewi hope this help you…
🙂