Ali
Ali

Reputation: 4245

`[[self tableView] reloadData]` changes the NSMutableArray count

I have an app that uses a UITablewView and in that TableView there is an NSMutableArray that holds the data to be displayed in the TabelView. The problem is in my TableView Controller I use:

[[self tableView] reloadData] 

To reload the TableView data and it works fine for a couple of times but doesn't work on the 3rd time and instead it changes the array count in a weird way.

Now I read similar question here and most likely I have 2 instances of the TableView or the TableViewController but I can't figure out how to troubleshoot this? How to detect if there are 2 instances of the object and fix that?

EDIT: Here is a pic how my navigation goes enter image description here

So the 1st round of going from ScrollView to TableView things show up correctly. Then I go to UIView and back to TableView and it's working fine. So I go back all the way to ScrollView and back again to TableView and it's good.

But when I go to the UIView for this time then back to TableView this problem happens. TableView doesn't display the changes. So I put a breakpoint just before [[self tableView] reloadData] and found out that the array _displayedObjetcs gets its count changed. -1 actually. see the following screen shots b4 and after I step over the reloadData just before reloadData and then

just after reloadData

Upvotes: 1

Views: 475

Answers (1)

Benjamin Mayo
Benjamin Mayo

Reputation: 6679

My immediate thought is that your array is not being retained properly, by your application. Your "weird" count is probably a number like 234791..., which is highly indicative of an array that has been released incorrectly. Therefore, I would check how your are retaining and releasing this array.

However, without more posted code, it is impossible to help you further.

Upvotes: 1

Related Questions