Saturday, 24 August 2013

UITableViewCell view after being dequeued from UITableView not empty

UITableViewCell view after being dequeued from UITableView not empty

I have a strange problem using the dequeueReusableCellWithIdentifier:
method of UITableView. Not sure if I don't understand the method well
enough or is it just plain weird. Here goes:
Im using a UITableView which presents some data to users, and inside my
- (UITableViewCell*)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath I use the dequeue method
like so:
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"cell"];
if (!cell)
cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
Afterwards I add some subviews to the contentView property of the cell.
When scrolling a bit further down on my table I see those previously added
subviews i.e. the cell is not empty but filled with "old" data. If I don't
dequeue, and just alloc-init a new one each time, the cells are empty but
I do see a bit more memory consumption which is precisely what Im trying
to bring down a little. I'm using ARC if that means anything here.
What or how should I tackle the problem? I have tried running a for loop
through the subviews of the content view and [view removeFromSuperview]
which does remove the previous views and brings down memory consumption a
little. But is that really necessary? Or is there a better way?

No comments:

Post a Comment