Question

I am working on an iPhone application which lists some items in a Table view. I encounter an error for the event TreasureList tableView:didSelectRowAtIndexPath while clicking on an item. I am confused over this error. The error is

[TreasureList tableView:didSelectRowAtIndexPath:]: message sent to deallocated instance 0x7ce0020

Code is as under:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

ProductModel *data=[[ProductModel alloc]init];
  data=[self.treasureData objectAtIndex:indexPath.row];

pid=  [NSString stringWithFormat: data.ID];//WithFormat:@"%@",data.ID];   

Please also let me know how can I debug the information "deallocated instance 0x7ce0020"

I am adding data to tableivew the following way.

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

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView
                         dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
                                  reuseIdentifier:SimpleTableIdentifier] autorelease];
}
ProductModel *data=[self.treasureData objectAtIndex:indexPath.row];
cell.textLabel.text = [NSString stringWithFormat:data.pName];
   [data
    release];
return cell; 
}
Was it helpful?

Solution

@Gijo You might get this error due to some already message being sent to already released Object which you are either using in your table cell , or When you are trying to use something in the

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

method, which has already being released viz some object, label etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top