Objective c 在UITableViewCell中选择后展开和折叠特定行

Objective c 在UITableViewCell中选择后展开和折叠特定行,objective-c,uitableview,Objective C,Uitableview,我正在尝试实现扩展/折叠表视图单元。它适用于许多行;单击后,可以展开和折叠它们 但是当我的表视图只有一行时会发生什么;当我单击它,然后所有其余的行也被扩展,即使它们是空的 这是我的代码: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if(selectedIndex == indexPath.row){ return 100

我正在尝试实现扩展/折叠表视图单元。它适用于许多行;单击后,可以展开和折叠它们

但是当我的表视图只有一行时会发生什么;当我单击它,然后所有其余的行也被扩展,即使它们是空的

这是我的代码:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(selectedIndex ==  indexPath.row){
        return 100;
    }else{
        return 44;
    }
}
//单元显示

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *cellIdentifier = @"CommentTableCell";
    //-- try to get a reusable cell --
    CommentTableCell *cell = (CommentTableCell *) [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    //-- create new cell if no reusable cell is available --
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:cellIdentifier owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    VocabularyController *vc;

    // Display word from database else display vocabulary when searching
    if (tableView != self.strongSearchDisplayController.searchResultsTableView) {
        vc = [self.myArray objectAtIndex:indexPath.row];
    }else{
        vc = [self.filteredArray objectAtIndex:indexPath.row];
    }
    cell.nameLabel.text = vc.korean;

    return cell;
}
//选定单元格

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

    if(selectedIndex == indexPath.row){
        selectedIndex = -1;

        NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:indexPath.row inSection:0];
        NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];

        [tableView beginUpdates];
        [tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationFade];
        [tableView endUpdates];
        return;
    }

    if(selectedIndex >= 0){
        NSIndexPath *previousPath = [NSIndexPath indexPathForRow:selectedIndex inSection:selectedSection];
        selectedIndex = indexPath.row;

        [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousPath] withRowAnimation:UITableViewRowAnimationFade];
    }

    // Finally set the selected index to the new selection and reload it to expand
    selectedIndex = indexPath.row;

    [tableView beginUpdates];
    [tableView endUpdates];
}
//我想显示我的屏幕截图。

当搜索后只有一个结果时,如何仅展开选定行?如何保持其他空的保持不变


谢谢你的阅读

我认为您无法更改单行表的行为——该表根据该行的高度显示单元格分隔符。如果您不想要这种外观,那么我认为您必须将分隔符样式设置为UITableViewCellSeparatorStyleNone。如果您只想在填充单元格的底部看到一条线,可以制作一个底部有一条线的自定义单元格,以模拟单元格分隔符。

我已经尝试过了。这没用。我的搜索结果表视图只包含一行,当我单击该行时,它会展开,但其他行也会展开。如何解决这个问题?Thank@MabKaaKoo,你试了什么?如果执行self.strongSearchDisplayController.searchResultsTableView.separatorStyle=UITableViewCellSeparatorStyleNone;,无论有多少行,都不应该看到任何分隔符。你是说你这么做了,你还看到行分隔符吗?@MabKaaKoo,如果它解决了你的问题,你应该接受答案。