动画后,UITableview单元格隐藏在节下。

时间:2013-10-30 16:24:48

标签: ios objective-c uitableview

所以我有一个包含3个不同部分的tableview,一旦你点击其中一个部分,一组单元格从该部分下拉。现在,我正在尝试让表格视图滚动到每个部分中的最后一个单元格。到目前为止我已经想出了这个:

[atableView beginUpdates];

    [atableView insertRowsAtIndexPaths:indexPathToInsert withRowAnimation:insertAnimation];
    [atableView setContentOffset:CGPointMake(0, self.view.bounds.size.height)];
    [atableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:deleteAnimation];

    [atableView endUpdates];

   self.openSectionIndex = section;

因此,当我使用这种方法时,它会像我想要的那样向上移动整个视图,但是一些顶部单元被切掉并隐藏在它们从下拉的部分下面。我可能过早地调用这个方法,并且在行完成动画之前调用它,或者它们是否在该部分下反弹。我能够拉下桌面视图,然后细胞从该部分下方出来。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

我实现了一个可折叠的部分组件,就像您所描述的那样,并且可以为您提供解决方案。

我的实现位于TLIndexPathTools库中。尝试运行“折叠”示例项目。展开第一部分。然后展开部分部分。您将看到,当单元格为动画时,表格会滚动显示屏幕上尽可能多的部分。

这样做的诀窍是要意识到你需要滚动到一个不一定存在的位置,因为表视图不会重新计算它的内容大小,直到过程中的某个时间。我使用的解决方案是将表视图的contentSize显式设置为包含要滚动到的位置的值。我的实现看起来像这样:

/*
 Force table to scroll to the specified location even if it is beyond the current
 content area. Use this to scroll to a future location during animiated table updates
 with the assumption that the location will be valid after the updates.
 */
- (void)forceTableScrollBasedOnExpectedSize:(CGFloat)scrollLocation animated:(BOOL)animated
{
    CGSize expectedMinimumContentSize = self.tableView.contentSize;
    if (expectedMinimumContentSize.height < scrollLocation) {
        // Temporarily expand the content area to contain the scroll location.
        // The table will overwrite this during the update process.
        expectedMinimumContentSize.height = scrollLocation;
        self.tableView.contentSize = expectedMinimumContentSize;
    }
    [self.tableView scrollRectToVisible:CGRectMake(0, scrollLocation-1, 1, 1) animated:animated];
}

其中scrollLocation是您想要显示的最底部位置。您可以在UITableViewController+ScrollOptimizer.m中查看更多详细信息。

我不确定这适用于您的问题。如果没有,请在您的问题中详细说明。

相关问题