2017-11-09 6 views
0

XCode9.1を使ってアプリケーションをビルドすると、このような奇妙な問題が発生しました。 私はシミュレータ(iOS 11とiOS 10)で実行しようとしていますが、結果は同じです。これはiOS 11のバグかXcodeのバグですか?ここでなぜiITableView sectionFooterViewは、iOS 11のセクショングループの下部に貼り付けるのではなく、画面の下部に浮いていますか?

enter image description here

完全なコードです。

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

あなたはfooterViewは、画面の一番下に浮遊している理由を私は把握したい問題があるsolution.Butと言うThanks.What UITableViewStyleGrouped –

+0

にテーブルビュースタイルを設定してみてください。 – Chao

答えて

0

意図したようにそれは働いていますが、それぞれのセクションの内側にスクロールしたときに、headerfooter section views両方がtable viewの上部と下部に取り付けられています。

0

フッターをセクションフッターとして保存している場合。それであなたが言及した方法は、バグではありません。フッターを画面の下部に貼り付ける場合は、tableviewのtableFooterViewプロパティを使用して、フッタービューとして割り当てることができます。

[self.tableView registerNib:[UINib nibWithNibName:@"FooterView" bundle:nil] forHeaderFooterViewReuseIdentifier:@"FooterView"]; 
FooterView *footerView = [[[NSBundle mainBundle] loadNibNamed:@"FooterView" owner:self options:nil] firstObject]; 
footerView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height); 

// Assigning the footer view to table footer view property 
self.infoTableView.tableFooterView = footerView; 
関連する問題