繁体   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