2011-02-27 46 views
0

我有使用自定义节标题视图的UITableView控制器。当我的设备是肖像时,它显示完美。而且,当我的设备再次呈现完美时。但是当在应用运行时期间改变方向时,它不会更新我的部分视图。有什么问题?iPhone - UITableViewController - 在纵向和横向设置节标题

使用下面的代码,我添加一个标签和两个按钮到一个视图,并返回该视图在“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

尝试设置观点autoresizing masks适当:例如用于headerView;

[headerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth]; 

和Add按钮和expandCollapseButton设置AutoresizingMask到:

UIViewAutoresizingMaskFlexibleLeftMargin 
+0

如果你看到我的代码,当过取向的改变,我创造了新的headerView。即使我尝试设置自动调整大小的蒙版。它没有帮助我。 – Satyam 2011-03-01 17:31:12

+0

而不是引用视图的框架使用界限,而是通常在添加子视图时使用界限,因为框架并不一定在您按照期望旋转UI时切换宽度和高度(它有点随意,我希望Apple修复) – 2011-03-01 18:01:14

+0

设置自动调整大小掩码修复我的问题。谢谢 – Philip007 2012-11-08 00:50:48