首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >UITableView tableFooterView显示在UITableView顶部-错误

UITableView tableFooterView显示在UITableView顶部-错误
EN

Stack Overflow用户
提问于 2017-09-26 01:59:04
回答 5查看 9.4K关注 0票数 12

我已经创建了一个非常简单的测试用例来重现这个问题。

我正在尝试以编程方式将页脚视图设置为表视图。请注意,我指的是表视图最底部的页脚,而不是区段页脚(大多数堆栈溢出答案都会混淆它们)。

下面是我非常简单的代码:

代码语言:javascript
复制
- (void)viewDidLoad {
    [super viewDidLoad];
    UIView *footerContainer = [[UIView alloc] initWithFrame:CGRectZero];
    footerContainer.backgroundColor=[UIColor greenColor];
    footerContainer.translatesAutoresizingMaskIntoConstraints=NO;
    [footerContainer addConstraints:@[[NSLayoutConstraint
                                       constraintWithItem:footerContainer attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual
                                       toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:100
                                       ],
                                      [NSLayoutConstraint
                                       constraintWithItem:footerContainer attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual
                                       toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0f constant:[UIScreen mainScreen].bounds.size.width
                                       ]]];

    self.mytableview.tableFooterView=footerContainer;
    [self.view setNeedsLayout];
    [self.view layoutIfNeeded];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text=[NSString stringWithFormat:@"%ld",indexPath.row];
    return cell;
}

然而,结果看起来像这样:

正如您注意到的,页脚显示在表视图的顶部。这是一个bug,还是我漏掉了什么?

如果我将tableFooterView更改为tableHeaderView,那么它可以正常工作。所以我希望footer也能用同样的方法,但事实并非如此。

EN

Stack Overflow用户

发布于 2018-05-13 23:19:00

请勿在分配给UIView上设置tableView.tableFooterView tableView.tableFooterView

在您的示例中,这是footerContainer。我也有同样的问题。问题的评论中提到了这一点,但我仍然花了几个小时进行故障排除,然后才注意到我正在做这件事,所以我把它放在这里作为一个可能的答案。

票数 31
EN
查看全部 5 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46411402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档