2010-05-31 67 views
0

我有一个使用自定义UITableViewCell(比如cell1)显示数据的tableview。触摸一行,我将自定义单元格更改为另一个自定义UITableViewCell(比如cell2)。此外,我增加所选单元格的行的大小,以适应更多的cell2项目。显示自定义UITableViewCell问题

我的问题是,当表格视图中的行数较少时,该方法正常工作。当行数增加时,这些行在触摸时扩展,但显示的数据与cell1的数据相同。 Cell2似乎根本没有加载。

期待很快回复....在此先感谢。

回答

0

我张贴我的代码....请让我知道如果有问题。

我的cellForRowAtIndexPath看起来是这样的:

- (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方法是这样的:

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



    selectedCellIndexPath = indexPath;  

    [tableView reloadData]; 

} 

heightForRowAtIndexPath看起来是这样的:

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

    if(selectedCellIndexPath != nil 

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

     return 110; 



    return 60;