【问题标题】:UITableView - scrolls sometimes when expanding a cell on 7.1, not on 7.0UITableView - 在 7.1 上展开单元格时有时会滚动,而不是在 7.0 上
【发布时间】:2014-04-05 09:07:18
【问题描述】:

此行为仅适用于 iOS 7.1,在 7.0 上,它按预期工作。

我有一个具有不同高度单元格的 UITableView。当点击其中一个时,它会通过

展开
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row != self.selectedCellIndexPath.row) {
        // Close previously opened cell
        if (self.selectedCellIndexPath != nil) {
            [tableView beginUpdates];
            [(MyTableViewCell *) [tableView cellForRowAtIndexPath:self.selectedCellIndexPath] collapse];
            [tableView endUpdates];
        }

        self.selectedCellIndexPath = indexPath;

        [tableView beginUpdates];
        [(MyTableViewCell *) [tableView cellForRowAtIndexPath:indexPath] expand];
        [tableView endUpdates];
    }
    else if (indexPath.row == self.selectedCellIndexPath.row) {
        self.selectedCellIndexPath = nil;
        [tableView beginUpdates];
        [(MyTableViewCell *) [tableView cellForRowAtIndexPath:indexPath] collapse];
        [tableView endUpdates];
    }
}

当点击 tableView 顶部的一行时,一切都按预期运行 - 单元格向下扩展,单元格顶部保持原位。但是当向下滚动并点击表格视图底部的一个单元格时,该单元格会向下移动并展开。细胞越往下越差。

我是这样计算表格单元格的高度的:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    self.prototypeCell = [[MyTableCell alloc] initReuseIdentifier:CellIdentifier];
    [self configureCell:self.prototypeCell forIndexPath:indexPath];

    float height = 38;
    if ([indexPath isEqual:self.selectedCellIndexPath]) {
        height += [self.prototypeCell expandedHeight] + 5;
    }

    return height;
}

如果我点击 tableView 顶部或底部的单元格,效果会有所不同,这让我很恼火。此外,这种效果只是向下滚动后的第一次。重复时,单元格按预期停留在其位置。只是再次上下滚动后,第一次出现错误。

【问题讨论】:

    标签: uitableview ios7.1


    【解决方案1】:

    我解决了问题;这是由于estimatedHeightForRowAtIndexPath,我删除了该方法,现在展开/折叠按预期工作。

    【讨论】:

    • 帮帮我,谢谢,如果你知道,你能解释一下原因吗
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多