-2

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; 
}
MACMAN
  • 1,883
  • 1
  • 21
  • 35
  • How can anyone help you? There's no code, no error info, nothing. You need to include the relevant code. – bryanmac Mar 23 '12 at 04:31
  • Add the code for your implementation of didSelectRowAtIndexPath plus any properties, objects, functions that it interacts with – bryanmac Mar 23 '12 at 04:33
  • Sorry, I have made the code available – MACMAN Mar 23 '12 at 04:45
  • Is that anything to do with the custom cell? – MACMAN Mar 23 '12 at 04:58
  • 1
    ProductModel *data=[[ProductModel alloc]init]; data=[self.treasureData objectAtIndex:indexPath.row]; These two lines makes no sense :-P, you do not need to allocate the 'data' as you are using it from your array, I am sure this 'data' is being released and you are using it later somewhere, what property type have you used for 'treasureData' – Rahul Sharma Mar 23 '12 at 05:03
  • How is treasureData defined in .h and how is it created. I wonder if it's deallocated by then. Also, if you set a break point in that method what line does it blow up on? – bryanmac Mar 23 '12 at 05:19
  • 1
    You do not need to release your data object, if your have not put an extra retain/copy somewhere while adding these ProductModel objects to your array. – Rahul Sharma Mar 23 '12 at 05:24
  • It is defined in .h file as @property (atomic,retain) NSMutableArray *treasureData; – MACMAN Mar 23 '12 at 05:25

1 Answers1

1

@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.

Rahul Sharma
  • 3,013
  • 1
  • 20
  • 47