简体   繁体   English

是否有可能仅在iOS6中调用tableView:viewForHeaderInSection方法?

[英]Is it possible that the tableView:viewForHeaderInSection method is ONLY called in iOS6?

I am building an app which should run on iOS7 and on iOS6. 我正在构建应在iOS7和iOS6上运行的应用程序。 For the iOS6 version I'm trying to achieve a similar look and feel than the iOS7 version. 对于iOS6版本,我试图实现与iOS7版本相似的外观。

Now I want to get the headerView of a section on iOS6 look similar to the one on iOS7. 现在,我想在iOS6上获得类似于iOS7上一节​​的headerView。

With the approach below its looks ok on iOS6. 使用以下方法,在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;
}

However, the issue I am facing now is that this is also applied to the iOS7 version. 但是,我现在面临的问题是这也适用于iOS7版本。 But in the iOS 7 version the header should appear as standard. 但在iOS 7版本中,标头应显示为标准标题。 So basically it would be great if there would be some way that this delegate method won't be called at all under iOS7. 因此,基本上,如果有某种方式可以在iOS7下完全不调用此委托方法,那将是很好的。 Is this possible? 这可能吗?

You can't make a particular version of iOS not call a standard delegate method that you have implemented. 您无法使特定版本的iOS不调用已实现的标准委托方法。 You could check the OS version and then supply an OS6 or OS7 specific class as the delegate, with different implementations for the methods. 您可以检查OS版本,然后提供OS6或OS7特定类作为委托,并为方法提供不同的实现。 Alternately you can just have your code run and not worry that you are explicitly creating the section header labels. 或者,您可以只运行代码,而不必担心要显式创建节标题标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM