tags:

views:

424

answers:

2

Hi all,

I have an NSArray of (Product) objects that are created by parsing an XML response from a server.

In the object, it has images, and text, and ints, URLs. etc.

There are 2 requests to the server 1: list of matching products from a search - small amount of detail 2: product details: the full details.

When the second request is parsed I am trying to update the existing object in the array.

- (void) setProduct:(Product *) _product atIndex: (int) index
{
    [_product retain];
    [productList replaceObjectAtIndex:index withObject:_product];
}

This doesn't seem to work as when I call update and table reloadData, the new values are not present.

Should I remove the object in the array first?

A: 
  1. You'll have to post more code from your data source methods. What you are doing here should work fine.
  2. Your "retain" method is unnecessary, you're leaking _product.
kubi
Yep, I was just checking why it was not copying the new values across."Build and Analyze" doesn't catch this tough. the problem was the index was 0. Thanks.
+3  A: 

replaceObjectAtIndex: is a method of NSMutableArray. So you would need to do make your productLists a NSMutableArray to use it.

Ross
I should have said NSMutableArray... good point.
you can edit your question to change it to NSMutableArray...
Ross