iPhone-UITableViewController-以纵向和横向设置节标题 [英] iPhone - UITableViewController - Setting section header in portrait and landscape

查看:57
本文介绍了iPhone-UITableViewController-以纵向和横向设置节标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用自定义节标题视图的UITableView控制器.当我的设备为人像时,显示完美.当我的设备处于横向时,它又是完美的.但是,当在应用运行时更改方向时,它不会更新我的剖面图.有什么问题吗?

I'm having UITableView controller which uses custom section header view. When my device is portrait, its showing perfect. And when my device is landscape its perfect again. But when orientation changed during app runtime, its not updating my section view. What's the problem?

使用以下代码,我向视图添加一个标签和两个按钮,并在"viewForHeaderInSection"中返回该视图.在调试过程中,我发现该方法正在被调用,但是节标题视图没有更新.

Using following code, I'm adding a label, and two buttons to a view and returning that view in "viewForHeaderInSection". During debugging I found that the method is getting called, but the section header view is not updating.

- (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];
}

推荐答案

尝试设置视图

Try setting the views autoresizing masks appropriately: eg for headerView;

[headerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];

,对于addButton和expandCollapseButton,将AutoresizingMask设置为:

and for addButton and expandCollapseButton set the AutoresizingMask to:

UIViewAutoresizingMaskFlexibleLeftMargin

这篇关于iPhone-UITableViewController-以纵向和横向设置节标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆