![](/img/trans.png)
[英]The tableview method viewForHeaderInSection is not called - Swift 5 / iOS14
[英]Is it possible that the tableView:viewForHeaderInSection method is ONLY called in iOS6?
我正在構建應在iOS7和iOS6上運行的應用程序。 對於iOS6版本,我試圖實現與iOS7版本相似的外觀。
現在,我想在iOS6上獲得類似於iOS7上一節的headerView。
使用以下方法,在iOS6上看起來不錯。
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
if (sectionTitle == nil) {
return nil;
}
// Create label with section title
UILabel *label = [[UILabel alloc] init];
label.font = [UIFont startProduktView_landLabelFont];
label.frame = CGRectMake(5, 6, 300, 30);
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor darkGrayColor];
label.shadowColor = [UIColor clearColor];
label.shadowOffset = CGSizeMake(0.0, 0.0);
label.text = sectionTitle;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 21)];
[view addSubview:label];
return view;
}
但是,我現在面臨的問題是這也適用於iOS7版本。 但在iOS 7版本中,標頭應顯示為標准標題。 因此,基本上,如果有某種方式可以在iOS7下完全不調用此委托方法,那將是很好的。 這可能嗎?
您無法使特定版本的iOS不調用已實現的標准委托方法。 您可以檢查OS版本,然后提供OS6或OS7特定類作為委托,並為方法提供不同的實現。 或者,您可以只運行代碼,而不必擔心要顯式創建節標題標簽。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.