tags:

views:

111

answers:

4

Hi!

I am trying to update data in a table view using a NSMutableArray. Quite simple :(

What is happening is that I get my data from a NSURLConnection Callback, which I parse and store it in an array and call reload data on the table view. The problem is that when cellForRowAtIndexPath is called back by the framework. The array still shows the correct count of the elements but all string objects I had stored earlier are shown as invalid.

Any pointers

A: 

Check that you are retaining the NSString objects in your NSURLConnection callback. Are you autoreleasing them?

Edit

Ok, forget that last thing. Double checking myself, NSMutableArray will automatically retain the objects when you add them to your array. So you won't need to retain them explicitly:

Like NSArray, instances of NSMutableArray maintain strong references to their contents. If you do not use garbage collection, when you add an object to an array, the object receives a retain message. When an object is removed from a mutable array, it receives a release message.

So you need to check you aren't doing any other explicit releases on the objects you are adding to the array. Are they referenced anywhere else?

Cannonade
A: 

The problem is there where you are adding the string object to a mutable array. The string object was already invalid that time. That's why the time you are accessing them from the array, they are invalid or do not exist.

So best thing is to check the code where you are adding the string object during the parsing.

Tushar
A: 

Hey,

Your problem may be that you have not initiated the array correctly.

Are you using the array as an attribute of the class?

Make sure when you load the view you allocate and initiate the array.

Seb Kade
+1  A: 

May be u problem is something like the below

NSString *value = [NSString stringWithFormat:@"%@",stringFromWebService];
[arrayOfObjects addObject:value];
[value release]; // This should not be released

this may not be exact but could be similar,

here value is obtained from class method of NSString which is an autoreleased object so if u can see it will be released twice, one by autorelease and other by you.

this is the area u need to check.

hope it helps

Regards Naveen RV

RVN