开发者

Problem in displaying custom UITableViewCell

I have a tableview displaying data using a custom UITableViewCell(say cell1). On touch of a row, I change the custom cell to another custom UITableViewCell(say cell2). Also I increase the size of row of the selected cell to accomodate, more items of cell2.

My problem is that the approach works fine when the number of rows in table view is less. When the number of rows increses, the rows expand on touching, but the data displayed is same as that of cell1. Cell2 doesn't seem to 开发者_JAVA技巧be loaded at all.

Looking forward for a reply soon....Thanks in advance.


I am posting my code....please let me know if there is a problem in that.

My cellForRowAtIndexPath looks like this:

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





    if(indexPath == selectedCellIndexPath)

    {



        static NSString *Identifier1 = @"Identifier1";

        Identifier1 = @"cell2";

        CustomCellController1 *cell = (CustomCellController1 *)[tableView dequeueReusableCellWithIdentifier:Identifier1];

        if(cell == nil) {

            [[NSBundle mainBundle] loadNibNamed:@"CustomCellController1View" owner:self options:nil];

            cell = rowTwoObject;

        }



        [cell setText:[test1Array objectAtIndex:indexPath.row]];    
        return cell;



    }



    else {





        static NSString *Identifier2 = @"Identifier2";

        Identifier2 = @"cell1";

        CustomCellController1 *cell = (CustomCellController1 *)[tableView dequeueReusableCellWithIdentifier:Identifier2];

        if(cell == nil) {

            [[NSBundle mainBundle] loadNibNamed:@"CustomCellController1View" owner:self options:nil];

            cell = rowOneObject;

        }



        [cell setText1:[temp1Array objectAtIndex:indexPath.row]];

        [cell setText2:[temp2Array objectAtIndex:indexPath.row]];



        return cell;  





    }



}

didSelectRowAtIndexPath looks like this:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {



    selectedCellIndexPath = indexPath;      

    [tableView reloadData];

}

heightForRowAtIndexPath looks like this:

    -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {  

    if(selectedCellIndexPath != nil  

       && [selectedCellIndexPath compare:indexPath] == NSOrderedSame)  

        return 110;  



    return 60;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜