views:

232

answers:

2

Hi,

currently I'm struggling with this problem: I got a UITableViewController that displays a tableView with different custom cells.

One custom cell displays a number (by a label). If you click on this cell, the navigationController moves to a UIPicker where the user can select the number to be displayes. If the user moves back, the cell should display the updated value.

Problem: I managed to reload the cells by calling

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  [self.tableView reloadData];
}

in the UITableViewController.

This works only, if I don't use dequeueReusableCellWithIdentifier for the cell (tables won't show updates otherwise). But in this case, memory usage grows and grows... In addition, the program crashes after about 15 movements to pickerView and back - I think because the cell that should be reloaded is already released.

How can I update a reusable custom cell every time the view appears ? What is the best solution ?

I think retaining cells should not be used ?

A: 

Have you set the appropriate id in the NIB? It has to be the same as you use when calling dequeueReusableCellWithIdentifier:

See step 3 here

epatel
+1  A: 

A general approach is to avoid reloading the whole table if only one cell is changed.

In such case, just get the reference to the UITableViewCell you want to "refresh" and invoke a [self setNeedsDisplay] from the main thread on it to trigger its refresh (will call the drawRect on it to trigger its drawing).

yonel