调用 reloadSections:withRowAnimation: 方法后,最初可见的单元格变得不可见

发布于 09-07 15:58 字数 1117 浏览 6 评论 0原文

我想显示一个具有多个部分的表格,并且最初仅显示 3 个部分元素。当用户点击节页脚时,节页脚会丢失(变为零),并且该节的所有元素将显示给用户。

因此,当用户点击节页脚时,我调用以下代码:

-(void)loadMoreRowsInSection:(NSInteger)section {
    [groupStates replaceObjectAtIndex:section withObject:[NSNumber numberWithBool:YES]];
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:NO];
}

我有以下代码来显示节页脚或不显示节页脚:

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    int count = [[(NSDictionary*)[filters objectAtIndex:section] valueForKeyPath:@"values.value"] count];
    if (count>3&&![[groupStates objectAtIndex:section] boolValue]) {
        LoadMoreFooter* loadMoreFooter = [[LoadMoreFooter alloc] initWithParent:self Section:section];
        return [loadMoreFooter view];
    }   
    else return nil;
}

当用户点击节页脚并调用 loadMoreRowsInSection 函数时,将重新加载此节,但当前行该部分消失。当我向上滚动,使行移出屏幕并再次进入时,行再次出现。

如果我调用 reloadData 而不是 reloadSections:withRowAnimation:,没有问题,但重新加载所有表似乎不是一个好主意。另外,reloadTable 中没有动画。

有人遇到过这个问题吗?

I want to display a table which has multiple sections and initally only 3 elements of sections are shown. When user taps the section footer, section footer gets lost (becomes nil) and all elements of that section will be shown to user.

For this reason, when the user taps the section footer, I call below code:

-(void)loadMoreRowsInSection:(NSInteger)section {
    [groupStates replaceObjectAtIndex:section withObject:[NSNumber numberWithBool:YES]];
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:section] withRowAnimation:NO];
}

I have the following code to show section footer or not:

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    int count = [[(NSDictionary*)[filters objectAtIndex:section] valueForKeyPath:@"values.value"] count];
    if (count>3&&![[groupStates objectAtIndex:section] boolValue]) {
        LoadMoreFooter* loadMoreFooter = [[LoadMoreFooter alloc] initWithParent:self Section:section];
        return [loadMoreFooter view];
    }   
    else return nil;
}

When user taps the section footer and loadMoreRowsInSection function is called, this section is reloaded but the current rows of that section disappear. When I scroll up down, making the rows go out of the screen and in again, rows appear again.

If I call reloadData instead of reloadSections:withRowAnimation:, there is no problem but it does not seem to be a good idea to reload all the table. Plus there is no animation in reloadTable.

Has anyone encountered this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

〃温暖了心ぐ2024-09-14 15:58:38

从您自己保留对它的引用的意义上来说,这是一个“静态”单元格吗?在这种情况下,问题可能是这样的:

当您进行动画重新加载时,表格视图将淡出现有单元格,同时淡入新单元格。问题是,当“新”单元格与旧单元格完全相同时,同一单元格将同时淡入和淡出!在您的情况下,淡出动画优先并且单元格被隐藏。

以下是一些可能的解决方案:

  1. 使用可重用的“包装单元”子类来代替静态单元 - 该单元的唯一用途是包含包装视图。然后,保留对视图的静态引用,并将它们添加到 cellForRowAtIndexPath:

    中出队的包装单元中,而

  2. 避免重新加载静态单元格的索引路径 - 而是执行 [UIViewtransitionWithView:self.myStaticCell持续时间:0.3 选项:UIViewAnimationOptionTransitionCrossDissolve 动画:nil 完成:nil]

Is this a "static" cell in the sense that you're keeping a reference to it yourself? In that case, the problem is probably this:

When you do an animated reload, the table view will fade out existing cells while at the same time fading in the new cells. The problem is that when the "new" cell is the exact same cell as the old one, the same cell will both fade in and fade out at the same time! And in your case, the fade out animation takes precedence and the cell is hidden.

Here are some possible solutions:

  1. Instead of static cells, have a reusable "wrapper cell" subclass - a cell whose only purpose is to contain a wrapped view. Then, keep static references to views instead, and add them to a dequeued wrapper cell in cellForRowAtIndexPath:

  2. Avoid reloading index paths of static cells - instead do [UIView transitionWithView:self.myStaticCell duration:0.3 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:nil]

清泪尽2024-09-14 15:58:38

我也有这个问题。我使用 UITableViewRowAnimationNone 来代替,它仍然会出于某种原因对该部分进行动画处理(而 reloadData 不会执行此操作),但它也会在动画后正确显示它。

I had this problem also. I used UITableViewRowAnimationNone instead, which still animates the section for some reason (which reloadData does not do) but it also displays it correctly after the animation.

空城缀染半城烟沙2024-09-14 15:58:38

在调用 reloadSections:withRowAnimation: 之后添加对 reloadData 的调用似乎可以修复消失的单元格问题,而不影响动画。

Adding a call to reloadData after the call to reloadSections:withRowAnimation: appears to fix the disappearing cell problem without affecting the animation.

知你几分2024-09-14 15:58:38

我遇到了类似的问题,节标题无论在哪里都会被卡住。尽管即使在屏幕上滚动/滚动时我的问题仍然存在:

iphone app Screenshot

我发现解决此问题的唯一方法是只需使用 reloadData 而不是 reloadSections:withRowAnimation:

I had a similar problem where the section headers would get stuck painted wherever they were. Although my issue persists even when scrolled on/off the screen:

iphone app screenshot

Only way I have found to fix it is to just use reloadData instead of reloadSections:withRowAnimation:.

冷夜2024-09-14 15:58:38

我的错误是:我有一个包含多个部分的 TableView。当我选择展开(并显示单元格)的部分时,上面的其他部分被隐藏。

我将标题视为单元格。

我的解决方案没有 reloadData()

内部重写 func viewDidLoad() 方法我使用了这段代码:

tableTeams.registerNib(UINib(nibName: "header", bundle: nil ), 
forCellReuseIdentifier: "HeaderCell")

但我应该使用这个:

tableTeams.registerNib(UINib(nibName: "header", bundle: nil),
forHeaderFooterViewReuseIdentifier: "HeaderCell")

并且在 func tableView(tableView : UITableView, viewForHeaderInSection 部分: Int) -> UIView?,我会使用这段代码:

func tableView(tableView: UITableView, viewForHeaderInSection section:
Int) -> UIView? {
      let cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("HeaderCell")
as! CustomHeaderUiView

我希望这有帮助!

My bug was that: I had a TableView with multiple sections. When I selected a section for expand (and show cells), other sections above that were hided.

I was treating header as cells.

My solution without reloadData():

inside override func viewDidLoad() method I was using this code:

tableTeams.registerNib(UINib(nibName: "header", bundle: nil ), 
forCellReuseIdentifier: "HeaderCell")

But I should have used this:

tableTeams.registerNib(UINib(nibName: "header", bundle: nil),
forHeaderFooterViewReuseIdentifier: "HeaderCell")

and inside func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView?, I would use this code:

func tableView(tableView: UITableView, viewForHeaderInSection section:
Int) -> UIView? {
      let cell = tableView.dequeueReusableHeaderFooterViewWithIdentifier("HeaderCell")
as! CustomHeaderUiView

I hope this helps!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文