2

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

2
  • 2
    Post some code. Are you retaining your array? What type of object are you storing in the array? If it is a class of your own, is that class properly retaining the things you put into it? Commented Mar 12, 2010 at 21:14
  • yes, you need to post some code as it could be a number of things. Commented Mar 21, 2010 at 17:43

4 Answers 4

1

Maybe your 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 you can see it will be released twice, one by autorelease and other by you.

This is the area you need to check.

Sign up to request clarification or add additional context in comments.

Comments

0

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?

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.