2014-02-10 6 views
1

Я пытаюсь создать пользовательский раздел TableView. Это выше, чем обычный заголовок раздела.Пользовательский раздел UITableView, не увеличивающий высоту

Проблема заключается в том, что, например, я увеличиваю высоту с 18 до 30. Ничего страшного не получится. Что я делаю не так?

у меня есть этот код:

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 18)]; 
    /* Create custom view to display section header... */ 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, tableView.frame.size.width, 18)]; 
    [label setFont:[UIFont boldSystemFontOfSize:12]]; 
    NSString *string =[[sectionsArray objectAtIndex:section] objectForKey:@"league"]; 
    /* Section header is in 0th index... */ 
    [label setText:string]; 
    [view addSubview:label]; 
    [view setBackgroundColor:[UIColor colorWithRed:166/255.0 green:177/255.0 blue:186/255.0 alpha:1.0]]; //your background color... 
    return view; 
} 
+0

Посмотреть UITableViewDelegate 'tableView: heightForHeaderInSection:' – vokilam

ответ

3

Реализуйте этот метод:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 
{ 
    return 18.0; // whatever height you want 
} 

Если вы используете IOS 7, вы можете использовать implemeent следующий метод также:

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection: (NSInteger)section NS_AVAILABLE_IOS(7_0); 
Смежные вопросы