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.
EDIT:
This is how I am displaying the ProfileViewController:
ProfileViewController* profileView = [[ProfileViewController alloc] initWithNibName:@"ProfileViewController" bundle:nil];
profileView.user_name = username;
profileView.message_source = messageSource;
[self.navigationController pushViewController:profileView animated:YES];
[profileView release];
Looks like your
ProfileViewControllerinstance is getting deallocated somehow. Make sure you’re not calling its-autoreleaseafter creating it.