【问题标题】:change uitableviewheader height更改uitableview标题高度
【发布时间】:2023-03-10 11:59:01
【问题描述】:

我有一个带有 UITableView 的 Storyboard。 tableView 得到一个 tableViewHeader 像:

----------------------
| Button             |
| Label              |
----------------------

该按钮仅在满足条件时出现。此外,如果单击按钮,标题必须是:

----------------------
| Label              |
----------------------

我尝试了很多东西,比如:

[UIView animateWithDuration:0.3 delay:0 options: UIViewAnimationCurveEaseOut
                     animations:^{
                         self.tableView.contentOffset = CGPointMake(0, 59);
                     }
                     completion:^(BOOL finished) {
                         if (finished) {
                             self.tableView.contentOffset = CGPointMake(0, 59);
                             self.viewButton.hidden = YES;
                         }
                     }
     ];

如果我单击按钮,这将非常有用。但是一旦我向上滚动表格视图,它会在 0 处反弹,然后偏移量丢失,我的表格视图看起来像:

----------------------
|                    |
| Label              |
----------------------

我也尝试了各种视图操作并尝试重置 tableViewHeader,例如:

    CGRect frame = self.tableView.tableHeaderView.frame;
frame.size.height = 31; 
self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:frame];
[self.tableView.tableHeaderView addSubview:self.viewTitle];

得到结果:

----------------------
|                    |
|            Label   |
----------------------

我看到了一些关于将我的 UITableViewController 更改为 UIViewController 的内容,我的问题将通过操纵视图控制器框架来解决,但我有 10 个表格视图,我真的没有时间进行我需要的所有更改。

请问有人可以帮我吗?

【问题讨论】:

    标签: objective-c ios


    【解决方案1】:

    我通过将相同的对象重新分配给表格视图标题解决了类似的问题:

    self.tableView.tableHeaderView = self.tableView.tableHeaderView;
    

    请注意,表格标题视图应该在此分配之前已经调整大小。

    【讨论】:

      【解决方案2】:

      不知道这是否只是复制/粘贴问题,但我认为当您更改标题框架时,您错过了一步;试试这个:

      CGRect frame = self.tableView.tableHeaderView.frame;
      frame.size.height = 31; 
      self.tableView.tableHeaderView.frame = frame;
      

      如果你省略了最后一个赋值,你只是创建了一个本地的CGRect 并修改了它的值,实际上并没有改变标题的框架。

      【讨论】:

      • self.tableView.tableHeaderView.frame = frame 导致约束崩溃。我试图分配一个新框架来解决这个问题。
      • 无法同时满足约束条件。将尝试通过打破约束 UIView:0x8d77fd0.bottom == UIView:0x8d767e0.bottom 来恢复。在 objc_exception_throw 上中断。
      【解决方案3】:

      我决定使用带有 UITableView 的 UIViewController。我的建议是:忘记 UITableViewController。这是一团糟。解决办法是:

      按钮:

      - (IBAction)synchronizeTouchUpInside:(id)sender {
      
          [UIView beginAnimations:nil context:NULL];
          [UIView setAnimationDuration:0.3];
          self.view.frame = CGRectMake(0, -59, 320, 367 + 59);
          [UIView commitAnimations];
      
      }
      

      viewWillAppear:

      - (void)viewWillAppear:(BOOL)animated {
      
          if (1 == 1) {
              self.view.frame = CGRectMake(0, -59, 320, 367 + 59);
          } else {
              self.view.frame = CGRectMake(0, 0, 320, 367);
          }
      
      }
      

      现在我只需要重建很多表视图控制器。生活吧。

      【讨论】:

        猜你喜欢
        • 2013-07-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-21
        • 2012-08-15
        • 1970-01-01
        • 1970-01-01
        • 2012-07-26
        相关资源
        最近更新 更多