2012-04-25 5 views
0

У меня есть TableView с разделами, разделы «Страны», и я беру их из моего основного объекта данных. Я установил фоновое изображение для своего стола, и теперь я хочу изменить цвет заголовка раздела. Как я могу это сделать? вот мой код до сих пор.изменить цвет заголовка раздела UITableView

-(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]; 

} 

когда я пытаюсь мой код я получаю сообщение об ошибке

ответ

1

Вам просто нужно возвращать строку (название) в этом методе. Выезд:

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

Здесь вы должны подгонять внешний вид.

+0

большое спасибо, это работает !!!! –

0

Если вы хотите изменить цвет ваших разделов в UITableView вы должны использовать этот метод из UITableViewDelegate:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
Смежные вопросы