我有一个使用自定义UITableViewCell(比如cell1)显示数据的tableview。在触摸一行时,我将自定义单元格更改为另一个自定义UITableViewCell(比如cell2)。此外,我增加了所选单元格的行的大小,以容纳更多的单元格2。
我的问题是,当表视图中的行数较少时,该方法可以正常工作。当行数增加时,行会在触摸时展开,但显示的数据与cell1的数据相同。 Cell2似乎根本没有加载。
期待尽快回复....提前致谢。
答案 0 :(得分: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;