PDA

View Full Version : How force TableView redraw itself




gandalfbp
Nov 6, 2009, 06:41 AM
Hi,

I have a TableView what loads it's cells from XIB's:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *MyIdentifier = @"MyIdentifier2";

GeoLoc *aGeoLoc = [appDelegate.ClosestArray objectAtIndex:indexPath.row];
if (haveStat) {
GeoLocCellWithSlots *aCell = (GeoLocCellWithSlots *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (aCell == nil){
[[NSBundle mainBundle] loadNibNamed:@"GeoLocCellWithSlots" owner:self options:nil];
aCell = geoCellWithSlots;
self.geoCellWithSlots = nil;
}
[aCell setGeoLoc:aGeoLoc];
return aCell;
}
else {
GeoLocCell *aCell = (GeoLocCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (aCell == nil){
[[NSBundle mainBundle] loadNibNamed:@"GeoLocCell" owner:self options:nil];
aCell = geoCell;
self.geoCell = nil;
}
[aCell setGeoLoc:aGeoLoc];
return aCell;
}
}


The two cells are different height. I set up the list's rowHeight in the viewDidLoad. The list contains only one kind of cells: either short ones, or tall ones, they are not mixed. If I set up the list from the taller, than the shorter, the cells are not redrawn correctly: some garbage will stay from the taller cell (the red, green, purple text).
How can I force the list to redraw itself completly?
What did I made wrong?



dejo
Nov 6, 2009, 08:43 AM
I set up the list's rowHeight in the viewDidLoad
I don't think you want to be setting row heights in viewDidLoad. That's too early. You might wanna try using UITableViewDelegate's tableView:heightForRowAtIndexPath: method.

PhoneyDeveloper
Nov 6, 2009, 09:03 AM
You need different identifiers for the two kinds of cells.

gandalfbp
Nov 9, 2009, 12:34 AM
You need different identifiers for the two kinds of cells.

Oh, my dearest friend, you saved my life. May thanks for the finding!

Peter