0

viewForHeaderInSection の textLabel の textColor は常に灰色です。BackgroundColor は期待どおりに変更されます。以下は、headerview を作成するコードです。「!headerView」状態になります。iOS SDK 7.1 の使用

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    static NSString *headerIdentifier = @"InspectionQuestionHeader";

    UITableViewHeaderFooterView *headerView = [tableView dequeueReusableHeaderFooterViewWithIdentifier:headerIdentifier];

    if (!headerView) {
        headerView = [[UITableViewHeaderFooterView alloc] initWithReuseIdentifier:headerIdentifier];
        headerView.contentView.backgroundColor = [UIColor grayColor];

        // Why doesn't this work?
        headerView.textLabel.textColor = [UIColor whiteColor];
    }

    InspectionQuestionSection *questionSection = _questionSections[section];
    NSString *title = [NSString stringWithFormat:@"%@. %@", questionSection.sectionNumber, questionSection.sectionDescription];
    headerView.textLabel.text = title;

    return headerView;
}
4

1 に答える 1

1

これは、別のデリゲート メソッドに入れたいものです。これを試して:

-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
UITableViewHeaderFooterView *headerIndexText = (UITableViewHeaderFooterView *)view;
[headerIndexText.textLabel setTextColor:[UIColor whiteColor]];
}
于 2014-06-11T15:10:03.167 に答える