重新加载部分而不重新加载部分标题 [英] Reload section without reloading section header

查看:148
本文介绍了重新加载部分而不重新加载部分标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableView ,其中标题视图中有 UISegmentedControl 。它应该与App Store应用程序完全相同:当用户滚动时,标题中的标题滚动屏幕,但 segmentedControl 粘在下navigationBar

I have a UITableView, where there is a UISegmentedControl in the header view. It should work exactly like in the App Store app: As the user scrolls, the title in the header scrolls off the screen but the segmentedControl sticks under the navigationBar.

当用户选择一个段时,标题下方的部分应重新加载一个漂亮的 UITableViewRowAnimation 。但是,当我调用 tableView:reloadSections:withRowAnimation:时,标题视图也是动画的,我想阻止它,因为它看起来很糟糕。

When the user selects a segment, the section below the header should be reloaded with a nice UITableViewRowAnimation. However, as I call tableView:reloadSections:withRowAnimation:, the header view is animated as well, which I want to prevent, because it looks terrible.

这是我的代码:

- (void)selectedSegmentIndexChanged:(UISegmentedControl *)sender
{
    int index = sender.selectedSegmentIndex;
    if (index < self.oldIndex) {
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationLeft];
    } else if (index > self.oldIndex) {
        [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationRight];
    }
    self.oldIndex = index;
}

任何人都知道如何重新加载标题下方的部分而不重新加载标题本身?

Anyone has an idea how to reload the section below the header without reloading the header itself?

推荐答案

也许你应该试试

[self.tableView reloadRowsAtIndexPaths:[self.tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationLeft] //or UITableViewRowAnimationRight

但是,我不确定,但我认为如果您重新加载的行数比以前少,可能会出现一些错误。

However, I'm not sure but I think it can rise some error in the case where you have less rows to reload than previously.

我认为你可以处理 [tableView beginUpdates] [tableView endUpdates] 来解决您的问题。

I think you could deal with [tableView beginUpdates] and [tableView endUpdates] to solve your problem.

例如,您要显示2个数据阵列。我们将它们命名为 oldArray newArray
你可以做什么的样本:

For example, you have 2 arrays of data to display. Let name them oldArray and newArray. A sample of how what you could do :

- (void)selectedSegmentIndexChanged:(UISegmentedControl *)sender
{
    [self.tableView setDataSource: newArray];
    int nbRowToDelete = [oldArray count];
    int nbRowToInsert = [newArray count];

    NSMutableArray *indexPathsToInsert = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < nbRowToInsert; i++) {
        [indexPathsToInsert addObject:[NSIndexPath indexPathForRow:i inSection:section]];
    }

    NSMutableArray *indexPathsToDelete = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < nbRowToDelete; i++) {
        [indexPathsToDelete addObject:[NSIndexPath indexPathForRow:i inSection:section]];
    }

    [self.tableView beginUpdates];
    [self.tableView deleteRowsAtIndexPaths:indexPathsToDelete withRowAnimation:UITableViewRowAnimationLeft];
    [self.tableView insertRowsAtIndexPaths:indexPathsToInsert withRowAnimation:UITableViewRowAnimationRight];
    [self.tableView endUpdates];
}

这篇关于重新加载部分而不重新加载部分标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆