1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

How force TableView redraw itself

Discussion in 'iPhone/iPad Programming' started by gandalfbp, Nov 6, 2009.

  1. macrumors newbie


    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?

    Attached Files:

    • x.png
      File size:
      73.3 KB
  2. Moderator


    Staff Member

    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.
  3. macrumors 68030


    You need different identifiers for the two kinds of cells.
  4. macrumors newbie

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


Share This Page