Memory problem with basic UITableView when scrolling

Posted by Sheehan Alam on Stack Overflow See other posts from Stack Overflow or by Sheehan Alam
Published on 2010-05-24T17:38:40Z Indexed on 2010/05/24 17:41 UTC
Read the original article Hit count: 365

I have a very simple UITableView that has 3 sections, and 3 rows per section.

#pragma mark -
#pragma mark UITableView delegate methods

- (NSInteger)tableView:(UITableView *)tblView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tblView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tblView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }

    // Configure the cell...

    return cell;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tblView 
{ 
    if (tblView == self.tableView) {
        return 3;
    }
    else {
        return 1; 
    }
}

Everything shows up fine, but as soon as I scroll my application crashes and my debugger tells me:

* -[ProfileViewController tableView:cellForRowAtIndexPath:]: message sent to deallocated instance 0x5ae61b0

I'm not exactly sure what I am doing wrong.

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c