iPhone - 的UITableViewController - 在纵向和横向设置节头(iPh

2019-11-05 00:28发布

我在其使用自定义区段标题视图的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];
}

Answer 1:

尝试设置的意见, 在自动口罩适当:例如用于headerView;

[headerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

和Add按钮和expandCollapseButton的AutoresizingMask设置为:

UIViewAutoresizingMaskFlexibleLeftMargin


文章来源: iPhone - UITableViewController - Setting section header in portrait and landscape