views:

123

answers:

2

Hi All,

Hope to get solution to this problem. I have been stuck on it since a long time now.

I have a a tableView which has custom labels drawn upon the cell using CGRect. I receive the data from a web service in arrays. Initially i display a line of data on the cells. When the user selects a cell, I call reloadsRowAtIndexPath to increase the height of selected row. In the process, cellForRowAtIndexPath gets called again. I keep track of this by a flag, and when cellForRowAtIndexPath gets called again, I display the two more lines of data from arrays, on the cell.

What i am getting is all overlapping data on one other. I tried to remove already placed labels in didSelectRowAtIndexPath, but to no avail.

Please help me on this

Thanks in advance.

A: 

Hi Vin,

In your cellForRowAtIndexPath method, when the selected row height needs to increase, do you create a new UITableViewCell object or change an already allocated one?

Please can you post your cellForRowAtIndexPath method code to help track this down?

EddieCatflap
A: 

Hi Eddie

My cellForRowAtIndexPath looks like this

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }

            // Set up the cell...
    /*if(is_TableRow_Clicked == FALSE)
    {

        //create custom label 1
        [cell.contentView addSubview:label1];
        labelCustomerID.text=@"IDs";


        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
    }
    else {

        //create custom label 2
        [cell.contentView addSubview:label2];
        labelCustomerID.text=@"IDs";  //ID label again


        //create custom label 3
        [cell.contentView addSubview:label3];
        labelCustomerID.text=@"Names";


        //create custom label 4
        [cell.contentView addSubview:label4];
        labelCustomerID.text=@"Addresses";

        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
        cell.clearsContextBeforeDrawing = TRUE;
        is_TableRow_Clicked == FALSE;
    } */


    return cell;
}

all the labels are declared globally and in my didSelectRowAtIndexPath I do this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    is_TableRow_Clicked = TRUE; 
    selectedCellIndexPath = indexPath;

    [label3 removeFromSuperview];
    [label4 removeFromSuperview];

    [theTableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];

}

and finally my heightForRowAtIndexPath looks like this:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {  
    // Note: Some operations like calling [tableView cellForRowAtIndexPath:indexPath]  
    // will call heightForRow and thus create a stack overflow  
    if(selectedCellIndexPath != nil  
       && [selectedCellIndexPath compare:indexPath] == NSOrderedSame)  
        return 90;  

    return 50;  

}  

Hope you can help me on this.

Vin