Reputation: 1321
I am working on an iPad app with a table view with standard cells, when a custom cell is selected, it should expand and load a custom nib file. This it does fine, for the first selection.
If I select a standard cell it loads the nib fine and if I select it again it goes back to normal, upon the second loading, it throws a EXC_BAD_ACCESS
error (I don't think I will ever get xcodes errors, seem to be the most abstract).
My code is below and the line is when it dequeues the cell for reuse, 3rd line:
if([listCells objectAtIndex:indexPath.row] == @"open") {
NSLog(@"Loading open cell at %i", indexPath.row);
CustomMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomMessageCell"];
//Loads the nib file and grabs the last object, presumably the table cell, as it is the only object in the file.
if(cell==nil) {
cell = [[[[NSBundle mainBundle] loadNibNamed:@"CustomMessageCell" owner:self options:nil] lastObject] autorelease];
}
UILabel *message = (UILabel *) [cell viewWithTag:1];
UIButton *approve = (UIButton *)[cell viewWithTag:4];
message.text = @"Test";
return cell;
Any help is greatly appreciated, thanks!
Upvotes: 2
Views: 601
Reputation: 878
Have you compiled and run on a real device? Sometimes you get more info then running just on the simulation.
Also other things to check:
Try also running your app (on a real device) and profile it using the Zombies and then Leaks profiling tools. (Instead of just "Run" choose "Profile").
Hope this helps.
Upvotes: 1
Reputation: 29767
You shouldn't autorelease
cell in this line:
cell = [[[[NSBundle mainBundle] loadNibNamed:@"CustomMessageCell"
owner:self options:nil] lastObject] autorelease];
Just create like this:
cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomMessageCell"
owner:self options:nil] lastObject];
Upvotes: 0