【问题标题】:Weird glitch in UITableView section header when reloading section above重新加载上面的部分时,UITableView 部分标题中出现奇怪的故障
【发布时间】:2013-05-19 01:11:47
【问题描述】:

看看this video

运行此代码时出现此故障:

[NSFetchedResultsController deleteCacheWithName:@"Root"];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"following == YES"];
[self.fetchedResultsController.fetchRequ­est setPredicate:predicate];
[self.fetchedResultsController performFetch:nil];
[self.tableView beginUpdates];
[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:THE_SECTION_WITH_THE_B­LOGS] withRowAnimation:UITableViewRowAnimation­Automatic];
[self.tableView endUpdates];

为什么我重新加载的部分下方的部分标题会像这样改变它的框架?有什么解决办法吗?

编辑:

这是我的视图ForHeaderInSection:

(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
if (tableView != self.tableView)
return nil;
BLMenuTableSectionHeaderView *view = nil;

if (section != BLMenuSectionUser) {
    view = [[BLMenuTableSectionHeaderView alloc] initWithFrame:CGRectZero];
    if (section == BLMenuSectionFollowing){
        if ([self blogCount] > 0){
            [view setTitle:NSLocalizedString(@"Following", nil)];
            [view addSubview:self.editButton];
        }else{
            self.tableView.editing = NO;
        }
    }
    if (section == BLMenuSectionPosts){
        [view setTitle:NSLocalizedString(@"Browse", nil)];
    }
    else if (section == BLMenuSectionSettings)
        [view setTitle:NSLocalizedString(@"Settings", nil)];
}

return view;
}

【问题讨论】:

  • 你的 tableView: headerViewForSection: 实现怎么样?
  • 您解决过这个问题吗?我看到了类似的东西。

标签: iphone ios objective-c uitableview


【解决方案1】:

Afaik,您不应该将 -beginUpdates-endUpdatesreload 结合使用,而应使用 when inserting or deleting

不确定这是否会导致您的问题,但可能值得一试。

无论动画类型如何,都一样吗?

来自Apple's docs

如果您想要后续的插入、删除和 选择操作(例如 cellForRowAtIndexPath: 和 indexPathsForVisibleRows) 同时进行动画处理。这组 方法必须以调用 endUpdates 结束。这些方法 对可以嵌套。如果您不进行插入、删除和 在这个块内的选择调用,表属性,如行数 可能会失效。 不应在组内调用 reloadData; 如果您在组内调用此方法,则需要执行任何 自己制作动画

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多