簡體   English   中英

是否有可能僅在iOS6中調用tableView:viewForHeaderInSection方法?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM