Ios 更改UITableView节标题的颜色

Ios 更改UITableView节标题的颜色,ios,core-data,Ios,Core Data,我有带部分的TableView,这些部分是国家,我从我的核心数据实体获取它们。我为我的tableview设置了一个背景图像,现在我想更改部分的标题颜色。我该怎么做?这是到目前为止我的代码 -(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { id <NSFetchedResultsSectionInfo> sectionInfo = [[self

我有带部分的TableView,这些部分是国家,我从我的核心数据实体获取它们。我为我的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];

}
-(NSString*)表视图:(UITableView*)表视图标题标题标题部分:(NSInteger)部分
{
id sectionInfo=[[self.fetchedResultsController节]objectAtIndex:section];
NSString*sectionTitle=[self tableView:tableView titleForHeaderInSection:section];
if(sectionTitle==nil){
返回零;
}
//创建带有节标题的标签
UILabel*label=[[UILabel alloc]init];
label.frame=CGRectMake(20,6300,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=节标题;
label.text=[sectionInfo name];
UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0,0,tableView.bounds.size.width,tableView.bounds.size.height)];
[视图添加子视图:标签];
返回[sectionInfo name];
}

当我尝试我的代码时,我得到一个错误

您只需要在该方法中返回一个字符串(标题)。退房:

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

这就是您应该定制外观的地方

如果要在UITableView中更改分区的颜色,应使用以下方法:

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