0

セクションを含むTableViewがあり、セクションは国であり、コアデータエンティティからそれらをフェッチします。テーブルビューの背景画像を設定しましたが、セクションのタイトルの色を変更したいと考えています。どうやってやるの?これまでの私のコードは次のとおりです。

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections]objectAtIndex:section];

    NSString *sectionTitle = [self tableView:tableView titleForHeaderInSection:section];
    if (sectionTitle == nil) {
        return nil;
    }

    // Create label with section title
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(20, 6, 300, 30);
    label.backgroundColor = [UIColor clearColor];
    label.textColor = [UIColor whiteColor];
    label.shadowColor = [UIColor blackColor];
    label.shadowOffset = CGSizeMake(0.0, 1.0);
    label.font = [UIFont boldSystemFontOfSize:16];
    //label.text = sectionTitle;
    label.text=[sectionInfo name];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width,tableView.bounds.size.height)];

    [view addSubview:label];

    return [sectionInfo name];

}

コードを試すとエラーが発生する

4

2 に答える 2

1

そのメソッドで文字列(タイトル)を返す必要があります。チェックアウト:

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

ここで、外観をカスタマイズする必要があります。

于 2012-04-25T09:18:26.957 に答える
0

UITableViewのセクションの色を変更する場合は、UITableViewDelegateから次のメソッドを使用する必要があります

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
于 2012-04-25T09:18:46.770 に答える