XCode9.1を使ってアプリケーションをビルドすると、このような奇妙な問題が発生しました。 私はシミュレータ(iOS 11とiOS 10)で実行しようとしていますが、結果は同じです。これはiOS 11のバグかXcodeのバグですか?ここでなぜiITableView sectionFooterViewは、iOS 11のセクショングループの下部に貼り付けるのではなく、画面の下部に浮いていますか?
完全なコードです。
- (void)viewDidLoad {
[super viewDidLoad];
UITableView *mainTableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
mainTableView.dataSource = self;
mainTableView.delegate = self;
mainTableView.rowHeight = 52.f;
[mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
[self.view addSubview:mainTableView];
UIView *headerView = [[UIView alloc] init];
headerView.backgroundColor = [UIColor orangeColor];
headerView.frame = CGRectMake(0, 0, CGRectGetWidth(self.view.frame), 270);
mainTableView.tableHeaderView = headerView;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (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:@"section=%ld-row=%ld",indexPath.section,indexPath.row];
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 15.f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 15.f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [UIView new];
headerView.backgroundColor = [UIColor redColor];
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 0, 200, 15);
label.text = [NSString stringWithFormat:@"Header section==%ld",section];
[headerView addSubview:label];
return headerView;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *headerView = [UIView new];
headerView.backgroundColor = [UIColor yellowColor];
UILabel *label = [[UILabel alloc] init];
label.frame = CGRectMake(0, 0, 200, 15);
label.text = [NSString stringWithFormat:@"Footer section==%ld",section];
[headerView addSubview:label];
return headerView;
}
あなたはfooterViewは、画面の一番下に浮遊している理由を私は把握したい問題があるsolution.Butと言うThanks.What UITableViewStyleGrouped –
にテーブルビュースタイルを設定してみてください。 – Chao