views:

30

answers:

1

I have 3 UITableViews on a UIView in which I load 3 different sets of data from NSMutableArrays. If I call [myTableView reloadData] the data kind of reloads - it actually gets added to the table along with what ever is already there. So 3 calls to reloadData results in triple listed information.

How do I prevent this from happening or how do I clear my tableView before I reload?

A: 

The most common cause of this is not reusing tableview cells. If you create a new cell for each logical row in the array (instead of dequeuing and reusing) the tableview may keep displaying all the cells. (*Edit:*probably won't happen.)

If not that, then it will be in one of the three methods that reloadData calls:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

Tableviews simply display the data. If the table duplicates then you're most likely duplicating the data in code somewhere. You want to make sure that one of these does not also cause the original source of the array to be read again and appended to the MutableArray that provides the data to the table.

TechZen
Creating new cells doesn't duplicate visible data. It will cause the old rows to be effectively leaked (more accurately, to be unnecessarily cached) if the cell was created with a reuse identifier. However, those cells will not be on-screen, they will simply be cached by the tableview.
Kevin Ballard
I seem to recall some piling up in some cases but I could be wrong.
TechZen