【问题标题】:Can i change the height of a uitableview's tableHeaderView?我可以更改 uitableview 的 tableHeaderView 的高度吗?
【发布时间】:2011-09-16 15:07:12
【问题描述】:

我正在尝试更改 tableView.tableHeaderView 框架,以便将其变大但没有效果。 tableView.tableHeaderView 的框架是固定的还是可调的?

【问题讨论】:

    标签: iphone objective-c ios uitableview


    【解决方案1】:
    tableView.tableHeaderView = nil;
    tableView.tableHeaderView = your_headerView;
    

    另请参阅:Resizing a UITableView's tableHeaderView

    【讨论】:

    • 我认为是因为 UITableView 在旋转或设置期间重新计算 tableHeaderView 高度。
    【解决方案2】:

    它很灵活,如果您尝试了以下代码但仍然无法正常工作, 然后尝试在界面生成器中更改标题视图大小。

    用你想要的 Header 创建一个 UIView 并添加视图

    UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, heightYouWant)];
    tempView.backgroundColor = [UIColor whiteColor];
    [yourTableView setTableHeaderView:tempView];
    //[yourTableView setTableFooterView:tempView]; you can also use Footer in same way
    [emptyView release];
    

    您可以在 tempView 中添加其他控件来创建它的运行时间。

    【讨论】:

      【解决方案3】:

      将此写入您的 UITableViewDelegate

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

      【讨论】:

      • 此解决方案适用于节标题视图——而不是 tableHeaderView
      猜你喜欢
      • 1970-01-01
      • 2017-02-13
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多