Заголовок в заголовке в UITableView не отображается? - PullRequest
1 голос
/ 22 сентября 2010

Я использую этот код для установки заголовка и цвета фона с помощью UITableView, но заголовок не отображается?

- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section
{
    return @"Contents";
}

- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *headerView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)] autorelease];
    [headerView setBackgroundColor:[UIColor brownColor]];
    [self.view sendSubviewToBack:headerView];

    return headerView;
}

Пожалуйста, помогите ...

Ответы [ 2 ]

1 голос
/ 25 сентября 2011

Если я правильно помню, когда вы возвращаете что-то для viewForHeaderInSection, значение, возвращенное в titleForHeaderInSection, больше не используется. В viewForHeaderInSection добавьте UILabel в качестве подпредставления к headerView и установите текст @"Contents"

0 голосов
/ 20 февраля 2013

Пожалуйста, измените ваш код на это и проверяйте только, что вы должны реализовать метод viewForHeaderInSection:

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

    NSString *cellValue = @"";
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 30)] ;
    [headerView setBackgroundColor:[UIColor brownColor]];

    UILabel *lblContent = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, headerView.frame.size.width,  headerView.frame.size.height)];
    cellValue = [[arrSections objectAtIndex:0] valueForKey:@"CategoryName"];
    lblContent.text = cellValue;
    [headerView addSubview:lblContent];
    return headerView;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...