iPhone - UITableViewController - Настройка заголовка раздела в портретной и альбомной ориентации - PullRequest
0 голосов
/ 27 февраля 2011

У меня есть контроллер UITableView, который использует пользовательский вид заголовка раздела.Когда мое устройство портретное, его показ идеален.И когда мое устройство в альбомной ориентации, его снова идеально.Но когда ориентация изменилась во время выполнения приложения, это не обновляет мой вид в разрезе.В чем проблема?

Используя следующий код, я добавляю метку и две кнопки в представление и возвращаю это представление в "viewForHeaderInSection".Во время отладки я обнаружил, что метод вызывается, но представление заголовка раздела не обновляется.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 80;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    NSDictionary* dict = [threadsArray objectAtIndex:section];

    UIView* headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 80)];
    headerView.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:0.2];

    UILabel *newLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 15, self.view.frame.size.width - 98, 21)];
    newLabel.textColor = [UIColor blackColor];
    newLabel.font = [UIFont boldSystemFontOfSize:17];
    newLabel.text = [dict objectForKey:@"Name"];
    newLabel.backgroundColor = [UIColor clearColor];
    [headerView addSubview:newLabel];

    UIButton* addButton = [UIButton buttonWithType:UIButtonTypeContactAdd];
    addButton.frame = CGRectMake(self.view.frame.size.width - 88, 11, 29, 29);
    NSLog(@"%f %f %f %f",addButton.frame.origin.x,addButton.frame.origin.y, addButton.frame.size.width,addButton.frame.size.height);
    [addButton addTarget:self action:@selector(addThreadResponseClicked:) forControlEvents:UIControlEventTouchDown];
    [headerView addSubview:addButton];

    UIButton* expandCollapseButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [expandCollapseButton setImage:[UIImage imageNamed:@"Expand.png"] forState:UIControlStateNormal];
    expandCollapseButton.frame = CGRectMake(self.view.frame.size.width - 48, 11, 29, 29);
    NSLog(@"%f %f %f %f",expandCollapseButton.frame.origin.x,expandCollapseButton.frame.origin.y, expandCollapseButton.frame.size.width,expandCollapseButton.frame.size.height);
    [expandCollapseButton addTarget:self action:@selector(expandCollapseHeader:) forControlEvents:UIControlEventTouchDown];
    [headerView addSubview:expandCollapseButton];

    addButton.tag = expandCollapseButton.tag = section;
    return [headerView autorelease];
}

1 Ответ

1 голос
/ 27 февраля 2011

Попробуйте установить представления автоматически изменяя размер маски соответственно: например, для headerView;

[headerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

и для addButton и expandCollapseButton установите AutoresizingMask равным:

UIViewAutoresizingMaskFlexibleLeftMargin
...