woutr_be
woutr_be

Reputation: 9722

App crashes when scrolling thru list

I've seen this problem with many others, went thru all the topics, but I can't seem to find a solution for it.

So I have a normal table view, with a cell linked to a .xib file, at first launch everything looks normal, but once I start scroll the app crashes immediately.

By enabling zombie objects I got to this error:

2012-05-03 16:18:13.008 coop_dev[27547:f803] * -[ActivityTableViewController tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x6853990

But I'm not sure what to look for or what might go wrong:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    ItemCell *cell = (ItemCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil) 
    {
        NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"ItemCell" owner:nil options:nil];
        cell = [topLevelObjects objectAtIndex:0];
    }

    Item *item = [self.activity objectAtIndex:indexPath.row];

    [[cell projectLabel] setText:item.project];
    [[cell descriptionLabel] setText:item.description];
    [[cell timeLabel] setText:item.time];
    [[cell timeAgoLabel] setText:item.timeAgo];
    //cell.avatar = [UIImageView item.avatar];

    cell.descriptionLabel.numberOfLines = 0;
    [cell.descriptionLabel sizeToFit];

    // remove the right arrow
    cell.accessoryType = UITableViewCellAccessoryNone;

    return cell;
} 

It works fine at first launch but after that just crashes

EDIT

I re-created the problem in a new project, just a basic table with some data, once you start scrolling it crashes. Download: http://dl.dropbox.com/u/274185/TestTable.zip

Upvotes: 0

Views: 321

Answers (3)

graver
graver

Reputation: 15213

In your FirstViewController.xib, remove the UITableViewController, but leave the UITableView. The crash happens because the File's Owner is already set as class FirstViewController in the Identity Inspector and it's like you have a second UITableViewController. Make sure also that the UITableView is hooked to the view outlet of the controller.

Upvotes: 2

Alexander
Alexander

Reputation: 8147

Check your ItemCell class' dealloc method, you're probably overreleasing something.

Upvotes: 0

MCKapur
MCKapur

Reputation: 9157

You are dequeueing code is a bit off... try mine:

     UITableViewCell *cell = [[UITableViewCell alloc] init];
cell = nil;
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
                                   reuseIdentifier:@"cell"]
            autorelease];


    cell.imageView.image = nil;
    cell.textLabel.text = nil;

}

Upvotes: 0

Related Questions