13

この問題を再現するための非常に簡単なテスト ケースを作成しました。

プログラムでフッター ビューをテーブルビューに設定しようとしています。テーブルビューの一番下にあるフッターを参照していることに注意してください-セクションフッターではありません(ほとんどのスタックオーバーフローの回答はそれらを混乱させます)。

これが私の非常に単純なコードです:

- (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;
}

ただし、結果は次のようになります。

ここに画像の説明を入力

お気づきのとおり、テーブルビューの上にフッターが表示されます。これはバグですか、それとも何か不足していますか?

tableFooterView を tableHeaderView に変更すると、正常に動作します。したがって、フッターでも同じことが機能することを期待していましたが、そうではありません。

4

6 に答える 6