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

时间:2014-09-14 21:37:05

标签: ios tableview

我正在构建一个应该在iOS7和iOS6上运行的应用程序。对于iOS6版本,我试图获得与iOS7版本类似的外观和感觉。

现在我想让iOS6上的一个部分的headerView看起来与iOS7上的一样。

使用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下根本不会调用这个委托方法会很棒。这可能吗?

1 个答案:

答案 0 :(得分:1)

您不能使特定版本的iOS不能调用您已实现的标准委托方法。您可以检查操作系统版本,然后提供OS6或OS7特定类作为委托,具有不同的方法实现。或者,您可以运行代码,而不必担心您是否明确创建了节标题标签。

相关问题