How to resize a tableHeaderView of a UITableView?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







96















I'm having trouble resizing a tableHeaderView. It simple doesn't work.



1) Create a UITableView and UIView (100 x 320 px);



2) Set the UIView as tableHeaderView of the UITableView;



3) Build and Go. Everything is ok.



Now, I want to resizing the tableHeaderView, so I add this code in viewDidLoad:



self.tableView.autoresizesSubviews = YES;

self.tableView.tableHeaderView = myHeaderView;
self.tableView.tableFooterView = myFooterView;

CGRect newFrame = self.tableView.tableHeaderView.frame;
newFrame.size.height = newFrame.size.height + 100;
self.tableView.tableHeaderView.frame = newFrame;


The height of the tableHeaderView should appear with 200, but appears with 100.



If I write:



self.tableView.autoresizesSubviews = YES;


CGRect newFrame = myHeaderView.frame;
newFrame.size.height = newFrame.size.height + 100;
myHeaderView.frame = newFrame;


self.tableView.tableHeaderView = myHeaderView;
self.tableView.tableFooterView = myFooterView;


Then it starts with 200 of height, as I want. But I want to be able to modify it in runtime.



I've also tried this, without success:



self.tableView.autoresizesSubviews = YES;

self.tableView.tableHeaderView = myHeaderView;
self.tableView.tableFooterView = myFooterView;

CGRect newFrame = self.tableView.tableHeaderView.frame;
newFrame.size.height = newFrame.size.height + 100;
self.tableView.tableHeaderView.frame = newFrame;

[self.tableView.tableHeaderView setNeedsLayout];
[self.tableView.tableHeaderView setNeedsDisplay];
[self.tableView setNeedsLayout];
[self.tableView setNeedsDisplay];


The point here is: How do we resize a tableHeaderView in runtime ???



Have anyone able to do this?



Thanks



iMe










share|improve this question































    96















    I'm having trouble resizing a tableHeaderView. It simple doesn't work.



    1) Create a UITableView and UIView (100 x 320 px);



    2) Set the UIView as tableHeaderView of the UITableView;



    3) Build and Go. Everything is ok.



    Now, I want to resizing the tableHeaderView, so I add this code in viewDidLoad:



    self.tableView.autoresizesSubviews = YES;

    self.tableView.tableHeaderView = myHeaderView;
    self.tableView.tableFooterView = myFooterView;

    CGRect newFrame = self.tableView.tableHeaderView.frame;
    newFrame.size.height = newFrame.size.height + 100;
    self.tableView.tableHeaderView.frame = newFrame;


    The height of the tableHeaderView should appear with 200, but appears with 100.



    If I write:



    self.tableView.autoresizesSubviews = YES;


    CGRect newFrame = myHeaderView.frame;
    newFrame.size.height = newFrame.size.height + 100;
    myHeaderView.frame = newFrame;


    self.tableView.tableHeaderView = myHeaderView;
    self.tableView.tableFooterView = myFooterView;


    Then it starts with 200 of height, as I want. But I want to be able to modify it in runtime.



    I've also tried this, without success:



    self.tableView.autoresizesSubviews = YES;

    self.tableView.tableHeaderView = myHeaderView;
    self.tableView.tableFooterView = myFooterView;

    CGRect newFrame = self.tableView.tableHeaderView.frame;
    newFrame.size.height = newFrame.size.height + 100;
    self.tableView.tableHeaderView.frame = newFrame;

    [self.tableView.tableHeaderView setNeedsLayout];
    [self.tableView.tableHeaderView setNeedsDisplay];
    [self.tableView setNeedsLayout];
    [self.tableView setNeedsDisplay];


    The point here is: How do we resize a tableHeaderView in runtime ???



    Have anyone able to do this?



    Thanks



    iMe










    share|improve this question



























      96












      96








      96


      38






      I'm having trouble resizing a tableHeaderView. It simple doesn't work.



      1) Create a UITableView and UIView (100 x 320 px);



      2) Set the UIView as tableHeaderView of the UITableView;



      3) Build and Go. Everything is ok.



      Now, I want to resizing the tableHeaderView, so I add this code in viewDidLoad:



      self.tableView.autoresizesSubviews = YES;

      self.tableView.tableHeaderView = myHeaderView;
      self.tableView.tableFooterView = myFooterView;

      CGRect newFrame = self.tableView.tableHeaderView.frame;
      newFrame.size.height = newFrame.size.height + 100;
      self.tableView.tableHeaderView.frame = newFrame;


      The height of the tableHeaderView should appear with 200, but appears with 100.



      If I write:



      self.tableView.autoresizesSubviews = YES;


      CGRect newFrame = myHeaderView.frame;
      newFrame.size.height = newFrame.size.height + 100;
      myHeaderView.frame = newFrame;


      self.tableView.tableHeaderView = myHeaderView;
      self.tableView.tableFooterView = myFooterView;


      Then it starts with 200 of height, as I want. But I want to be able to modify it in runtime.



      I've also tried this, without success:



      self.tableView.autoresizesSubviews = YES;

      self.tableView.tableHeaderView = myHeaderView;
      self.tableView.tableFooterView = myFooterView;

      CGRect newFrame = self.tableView.tableHeaderView.frame;
      newFrame.size.height = newFrame.size.height + 100;
      self.tableView.tableHeaderView.frame = newFrame;

      [self.tableView.tableHeaderView setNeedsLayout];
      [self.tableView.tableHeaderView setNeedsDisplay];
      [self.tableView setNeedsLayout];
      [self.tableView setNeedsDisplay];


      The point here is: How do we resize a tableHeaderView in runtime ???



      Have anyone able to do this?



      Thanks



      iMe










      share|improve this question
















      I'm having trouble resizing a tableHeaderView. It simple doesn't work.



      1) Create a UITableView and UIView (100 x 320 px);



      2) Set the UIView as tableHeaderView of the UITableView;



      3) Build and Go. Everything is ok.



      Now, I want to resizing the tableHeaderView, so I add this code in viewDidLoad:



      self.tableView.autoresizesSubviews = YES;

      self.tableView.tableHeaderView = myHeaderView;
      self.tableView.tableFooterView = myFooterView;

      CGRect newFrame = self.tableView.tableHeaderView.frame;
      newFrame.size.height = newFrame.size.height + 100;
      self.tableView.tableHeaderView.frame = newFrame;


      The height of the tableHeaderView should appear with 200, but appears with 100.



      If I write:



      self.tableView.autoresizesSubviews = YES;


      CGRect newFrame = myHeaderView.frame;
      newFrame.size.height = newFrame.size.height + 100;
      myHeaderView.frame = newFrame;


      self.tableView.tableHeaderView = myHeaderView;
      self.tableView.tableFooterView = myFooterView;


      Then it starts with 200 of height, as I want. But I want to be able to modify it in runtime.



      I've also tried this, without success:



      self.tableView.autoresizesSubviews = YES;

      self.tableView.tableHeaderView = myHeaderView;
      self.tableView.tableFooterView = myFooterView;

      CGRect newFrame = self.tableView.tableHeaderView.frame;
      newFrame.size.height = newFrame.size.height + 100;
      self.tableView.tableHeaderView.frame = newFrame;

      [self.tableView.tableHeaderView setNeedsLayout];
      [self.tableView.tableHeaderView setNeedsDisplay];
      [self.tableView setNeedsLayout];
      [self.tableView setNeedsDisplay];


      The point here is: How do we resize a tableHeaderView in runtime ???



      Have anyone able to do this?



      Thanks



      iMe







      iphone cocoa-touch uitableview






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Feb 18 '11 at 5:18









      JOM

      6,294569108




      6,294569108










      asked Dec 4 '08 at 16:43









      iMeiMe

      481165




      481165
























          18 Answers
          18






          active

          oldest

          votes


















          179














          FYI: I've gotten this to work by modifying the tableHeaderView and re-setting it. In this case, i'm adjusting the size of the tableHeaderView when the UIWebView subview has finished loading.



          [webView sizeToFit];
          CGRect newFrame = headerView.frame;
          newFrame.size.height = newFrame.size.height + webView.frame.size.height;
          headerView.frame = newFrame;
          [self.tableView setTableHeaderView:headerView];





          share|improve this answer



















          • 13





            +1 This worked for me. Calling 'setTableHeaderView' after your subview has changed size is the key. The problem is, my subview changes size over a second as an animation. Now I'm trying to figure out how to animate the tableHeaderView with it.

            – Andrew
            Jan 18 '10 at 7:56






          • 1





            Perfect, thanks a bunch. To me, this is an example of one of the less desirable qualities of properties in Objective-C. There's no way for us to know (and no reason we should know) that setting the header has the side effect of recalculating the height. It should either do it automatically when we update the header's height, or we should be required to call something like [tableView recalculateHeaderHeight] every time.

            – jakeboxer
            Dec 1 '10 at 17:05








          • 48





            @Andrew I know this is almost a year too late, but better late then never: I was able to animate the changing height of the table header view by wrapping the setTableHeaderView: call with [tableview beginUpdates] and [tableview endUpdates]

            – jasongregori
            Nov 15 '11 at 1:10








          • 2





            @jasongregori handy comment you added - i'm seeing that the same technique (beginUpdates+endUpdates) does not animate the height change for a tableFooterView the way it does a tableHeaderView. Have you figured out a good way to animate the tableFooterView as well?

            – kris
            Dec 5 '11 at 23:32






          • 1





            Impressive, it event works when doing it inside a UIView animation block, although I don't think it's very efficient in that case.

            – Can
            May 5 '12 at 0:56



















          12














          This answer is old and apparently doesn't work on iOS 7 and above.



          I ran into the same problem, and I also wanted the changes to animate, so I made a subclass of UIView for my header view and added these methods:



          - (void)adjustTableHeaderHeight:(NSUInteger)newHeight{
          NSUInteger oldHeight = self.frame.size.height;
          NSInteger originChange = oldHeight - newHeight;

          [UIView beginAnimations:nil context:nil];

          [UIView setAnimationDuration:1.0f];
          [UIView setAnimationDelegate:self];
          [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

          self.frame = CGRectMake(self.frame.origin.x,
          self.frame.origin.y,
          self.frame.size.width,
          newHeight);

          for (UIView *view in [(UITableView *)self.superview subviews]) {
          if ([view isKindOfClass:[self class]]) {
          continue;
          }
          view.frame = CGRectMake(view.frame.origin.x,
          view.frame.origin.y - originChange,
          view.frame.size.width,
          view.frame.size.height);
          }

          [UIView commitAnimations];
          }

          - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
          [(UITableView *)self.superview setTableHeaderView:self];
          }


          This essentially animates all the subviews of the UITableView that aren't the same class type as the calling class. At the end of the animation, it calls setTableHeaderView on the superview (the UITableView) – without this the UITableView contents will jump back the next time the user scrolls. The only limitation I've found on this so far is if the user attempts to scroll the UITableView while the animation is taking place, the scrolling will animate as if the header view hasn't been resized (not a big deal if the animation is quick).






          share|improve this answer


























          • works perfectly, removed the animation because I didn't need it.

            – Jiho Kang
            May 21 '12 at 13:18











          • Worked perfect until iOS7 happend... added my solution below

            – avishic
            Sep 24 '13 at 15:54






          • 1





            WTF? You're messing so much with the internals of UITableView that you really shouldn't be surprised that it doesn't work in newer iOS versions... ;)

            – Daniel Rinser
            Mar 27 '14 at 9:07



















          10














          If you want to conditionally animate the changes you can do the following:



          - (void) showHeader:(BOOL)show animated:(BOOL)animated{

          CGRect closedFrame = CGRectMake(0, 0, self.view.frame.size.width, 0);
          CGRect newFrame = show?self.initialFrame:closedFrame;

          if(animated){
          // The UIView animation block handles the animation of our header view
          [UIView beginAnimations:nil context:nil];
          [UIView setAnimationDuration:0.3];
          [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

          // beginUpdates and endUpdates trigger the animation of our cells
          [self.tableView beginUpdates];
          }

          self.headerView.frame = newFrame;
          [self.tableView setTableHeaderView:self.headerView];

          if(animated){
          [self.tableView endUpdates];
          [UIView commitAnimations];
          }
          }


          Please note that the animation is two-folded:




          1. The animation of the cells below the tableHeaderView. This is done using beginUpdates and endUpdates

          2. The animation of the actual header view. This is done using a UIView animation block.


          In order to synchronize those two animations the animationCurve has to be set to UIViewAnimationCurveEaseInOut and the duration to 0.3, which seems to be what the UITableView uses for it's animation.



          Update



          I created an Xcode project on gihub, which does this.
          Check out the project ResizeTableHeaderViewAnimated in besi/ios-quickies



          screenshot






          share|improve this answer





















          • 2





            This technique does work, but it doesn't work for table views with section headers. When you use begin updates/end updates it interferes with the animation block, leaving duplicate section headers.

            – BlueFish
            Aug 15 '13 at 0:27



















          8














          I think it should work if you just set the height of myHeaderView like so:



          CGRect newFrame = myHeaderView.frame;
          newFrame.size.height = newFrame.size.height + 100;
          myHeaderView.frame = newFrame;

          self.tableView.tableHeaderView = myHeaderView;





          share|improve this answer
























          • This actually works, but only if used in viewDidLayoutSubviews

            – KoCMoHaBTa
            Dec 22 '14 at 17:43



















          6














          Used @garrettmoon solution above until iOS 7.

          Here's an updated solution based on @garrettmoon's:



          - (void)adjustTableHeaderHeight:(NSUInteger)newHeight animated:(BOOL)animated {

          [UIView beginAnimations:nil context:nil];

          [UIView setAnimationDuration:[CATransaction animationDuration]];
          [UIView setAnimationDelegate:self];
          [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

          self.frame = CGRectMake(self.frame.origin.x,
          self.frame.origin.y,
          self.frame.size.width,
          newHeight);

          [(UITableView *)self.superview setTableHeaderView:self];

          [UIView commitAnimations];
          }

          - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
          [(UITableView *)self.superview setTableHeaderView:self];
          }





          share|improve this answer































            5














            This worked for me on iOS 7 and 8. This code is running on the table view controller.



            [UIView animateWithDuration:0.3 animations:^{
            CGRect oldFrame = self.headerView.frame;
            self.headerView.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, oldFrame.size.width, newHeight);
            [self.tableView setTableHeaderView:self.headerView];
            }];





            share|improve this answer
























            • Thanks a lot. This works great ! :)

              – Hemang
              Sep 2 '15 at 9:27



















            4














            Its because the setter of tableHeaderView.



            You have to set the UIView height before set the tableHeaderView. (Would be much easier if Apple open sources this framework...)






            share|improve this answer































              3














              On iOS 9 and below, tableHeaderView would not re-layout after resizing it.
              This issue is resolved in iOS 10.



              To solve this issue, just do it with the following code:



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





              share|improve this answer































                2














                On iOS 9.x, doing this on viewDidLoad works just fine:



                var frame = headerView.frame
                frame.size.height = 11 // New size
                headerView.frame = frame


                headerView is declared as @IBOutlet var headerView: UIView! and connected on the storyboard, where it is placed at the top of the tableView, to function as the tableHeaderView.






                share|improve this answer

































                  1














                  Setting the height for header view property tableView.tableHeaderView in viewDidLoad seems not work, the header view height still not change as expected.



                  After fighting against this issue for many tries. I found that, you can change the height by invoking the header view create logic inside the
                  - (void)didMoveToParentViewController:(UIViewController *)parent method.



                  So the example code would look like this:



                  - (void)didMoveToParentViewController:(UIViewController *)parent {
                  [super didMoveToParentViewController:parent];

                  if ( _tableView.tableHeaderView == nil ) {
                  UIView *header = [[[UINib nibWithNibName:@"your header view" bundle:nil] instantiateWithOwner:self options:nil] firstObject];

                  header.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), HeaderViewHeight);

                  [_tableView setTableHeaderView:header];
                  }
                  }





                  share|improve this answer































                    0














                    I found the initWithFrame initializer of a UIView doesn't properly honor the rect I pass in. Hence, I did the following which worked perfectly:



                     - (id)initWithFrame:(CGRect)aRect {

                    CGRect frame = [[UIScreen mainScreen] applicationFrame];

                    if ((self = [super initWithFrame:CGRectZero])) {

                    // Ugly initialization behavior - initWithFrame will not properly honor the frame we pass
                    self.frame = CGRectMake(0, 0, frame.size.width, 200);

                    // ...
                    }
                    }


                    The advantage of this is it is better encapsulated into your view code.






                    share|improve this answer
























                    • Fetching the frame from UIScreen is a bad idea, how will you re-use your view?

                      – Zorayr
                      Apr 14 '16 at 19:44



















                    0














                    I have implemented animated height change of the table's header to expand to overall screen when tapped. However, the code can help in other cases:



                    // Swift
                    @IBAction func tapped(sender: UITapGestureRecognizer) {

                    self.tableView.beginUpdates() // Required to update cells.

                    // Collapse table header to original height
                    if isHeaderExpandedToFullScreen {

                    UIView.animateWithDuration(0.5, animations: { () -> Void in
                    self.scrollView.frame.size.height = 110 // original height in my case is 110
                    })

                    }
                    // Expand table header to overall screen
                    else {
                    let screenSize = self.view.frame // "screen" size

                    UIView.animateWithDuration(0.5, animations: { () -> Void in
                    self.scrollView.frame.size.height = screenSize.height
                    })
                    }

                    self.tableView.endUpdates() // Required to update cells.

                    isHeaderExpandedToFullScreen= !isHeaderExpandedToFullScreen // Toggle
                    }





                    share|improve this answer































                      0














                      UITableView resizing header - UISearchBar with Scope Bar



                      I wanted a UITableView with a UISearchBar as the header to the table so I have a hierarchy that looks like this



                      UITableView
                      |
                      |--> UIView
                      | |--> UISearchBar
                      |
                      |--> UITableViewCells


                      UISearchBarDelegate methods



                      As has been stated elsewhere, if you don't setTableViewHeader after changing it, nothing will happen.



                      - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
                      {
                      searchBar.showsScopeBar = YES;
                      [UIView animateWithDuration:0.2f animations:^{
                      [searchBar sizeToFit];
                      CGFloat height = CGRectGetHeight(searchBar.frame);

                      CGRect frame = self.tableView.tableHeaderView.frame;
                      frame.size.height = height;
                      self.tableHeaderView.frame = frame;
                      self.tableView.tableHeaderView = self.tableHeaderView;
                      }];

                      [searchBar setShowsCancelButton:YES animated:YES];
                      return YES;
                      }

                      - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
                      {
                      searchBar.showsScopeBar = NO;
                      [UIView animateWithDuration:0.f animations:^{
                      [searchBar sizeToFit];

                      CGFloat height = CGRectGetHeight(searchBar.frame);

                      CGRect frame = self.tableView.tableHeaderView.frame;
                      frame.size.height = height;
                      self.tableHeaderView.frame = frame;
                      self.tableView.tableHeaderView = self.tableHeaderView;
                      }];

                      [searchBar setShowsCancelButton:NO animated:YES];
                      return YES;
                      }





                      share|improve this answer































                        0














                        If custom headerView is designed using autolayout and headerView needs to be updated after web-fetch or similar lazy task.
                        then in iOS-Swift I did this and got my headerView updated using bellow code:



                        //to reload your cell data
                        self.tableView.reloadData()
                        dispatch_async(dispatch_get_main_queue(),{
                        // this is needed to update a specific tableview's headerview layout on main queue otherwise it's won't update perfectly cause reloaddata() is called
                        self.tableView.beginUpdates()
                        self.tableView.endUpdates()
                        }





                        share|improve this answer































                          0














                          Obviously, by now Apple should have implemented UITableViewAutomaticDimension for tableHeaderView & tableFooterView...



                          The following seems to work for me using layout contraint(s):



                          CGSize   s  = [ self  systemLayoutSizeFittingSize : UILayoutFittingCompressedSize ];
                          CGRect f = [ self frame ];

                          f.size = s;

                          [ self setFrame : f ];





                          share|improve this answer































                            0














                            If your tableHeaderView is a content adjustable webView,you can try:



                            [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];

                            - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
                            self.webView.height = self.webView.scrollView.contentSize.height;
                            self.tableView.tableHeaderView = self.webView;
                            }


                            I tested it on iOS9 and iOS11,worked well.






                            share|improve this answer































                              0














                              This is only for when you use auto-layout and set translatesAutoresizingMaskIntoConstraints = false to a custom header view.



                              The best and the simplest way is to override intrinsicContentSize. Internally UITableView uses intrinsicContentSize to decide its header/footer size. Once you have override intrinsicContentSize in your custom view, What you need to do is as below




                              1. configure the custom header/footer view's layout(subviews)

                              2. invoke invalidateIntrinsicContentSize()

                              3. invoke tableView.setNeedsLayout() and tableView.layoutIfNeeded()


                              Then the UITableView's header/footer will be updated as you want. No need to set the view nil or reset.



                              One thing really interesting for the UITableView.tableHeaderView or .tableFooterView is that UIStackView loose its ability to manage its arrangedSubviews. If you want to use UIStackView as a tableHeaderView or tableFooterView, you have to embed the stackView in a UIView and override UIView's intrinsicContentSize.






                              share|improve this answer

































                                -3














                                Did you try
                                [self.tableView reloadData] after changing the height?






                                share|improve this answer
























                                • I've tried this but the header didn't resized.

                                  – wal
                                  Aug 19 '10 at 20:22











                                • didnt work either

                                  – khalil
                                  Jan 10 '13 at 8:56






                                • 1





                                  It's about the tableHeaderView, which is a static view. - [UITableView reloadData] is only intended for the dynamic views (cells) and also the sectionHeaders which you obviously thought were meant ;)

                                  – Julian F. Weinert
                                  Jul 16 '15 at 11:29












                                Your Answer






                                StackExchange.ifUsing("editor", function () {
                                StackExchange.using("externalEditor", function () {
                                StackExchange.using("snippets", function () {
                                StackExchange.snippets.init();
                                });
                                });
                                }, "code-snippets");

                                StackExchange.ready(function() {
                                var channelOptions = {
                                tags: "".split(" "),
                                id: "1"
                                };
                                initTagRenderer("".split(" "), "".split(" "), channelOptions);

                                StackExchange.using("externalEditor", function() {
                                // Have to fire editor after snippets, if snippets enabled
                                if (StackExchange.settings.snippets.snippetsEnabled) {
                                StackExchange.using("snippets", function() {
                                createEditor();
                                });
                                }
                                else {
                                createEditor();
                                }
                                });

                                function createEditor() {
                                StackExchange.prepareEditor({
                                heartbeatType: 'answer',
                                autoActivateHeartbeat: false,
                                convertImagesToLinks: true,
                                noModals: true,
                                showLowRepImageUploadWarning: true,
                                reputationToPostImages: 10,
                                bindNavPrevention: true,
                                postfix: "",
                                imageUploader: {
                                brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
                                contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
                                allowUrls: true
                                },
                                onDemand: true,
                                discardSelector: ".discard-answer"
                                ,immediatelyShowMarkdownHelp:true
                                });


                                }
                                });














                                draft saved

                                draft discarded


















                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f341256%2fhow-to-resize-a-tableheaderview-of-a-uitableview%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown

























                                18 Answers
                                18






                                active

                                oldest

                                votes








                                18 Answers
                                18






                                active

                                oldest

                                votes









                                active

                                oldest

                                votes






                                active

                                oldest

                                votes









                                179














                                FYI: I've gotten this to work by modifying the tableHeaderView and re-setting it. In this case, i'm adjusting the size of the tableHeaderView when the UIWebView subview has finished loading.



                                [webView sizeToFit];
                                CGRect newFrame = headerView.frame;
                                newFrame.size.height = newFrame.size.height + webView.frame.size.height;
                                headerView.frame = newFrame;
                                [self.tableView setTableHeaderView:headerView];





                                share|improve this answer



















                                • 13





                                  +1 This worked for me. Calling 'setTableHeaderView' after your subview has changed size is the key. The problem is, my subview changes size over a second as an animation. Now I'm trying to figure out how to animate the tableHeaderView with it.

                                  – Andrew
                                  Jan 18 '10 at 7:56






                                • 1





                                  Perfect, thanks a bunch. To me, this is an example of one of the less desirable qualities of properties in Objective-C. There's no way for us to know (and no reason we should know) that setting the header has the side effect of recalculating the height. It should either do it automatically when we update the header's height, or we should be required to call something like [tableView recalculateHeaderHeight] every time.

                                  – jakeboxer
                                  Dec 1 '10 at 17:05








                                • 48





                                  @Andrew I know this is almost a year too late, but better late then never: I was able to animate the changing height of the table header view by wrapping the setTableHeaderView: call with [tableview beginUpdates] and [tableview endUpdates]

                                  – jasongregori
                                  Nov 15 '11 at 1:10








                                • 2





                                  @jasongregori handy comment you added - i'm seeing that the same technique (beginUpdates+endUpdates) does not animate the height change for a tableFooterView the way it does a tableHeaderView. Have you figured out a good way to animate the tableFooterView as well?

                                  – kris
                                  Dec 5 '11 at 23:32






                                • 1





                                  Impressive, it event works when doing it inside a UIView animation block, although I don't think it's very efficient in that case.

                                  – Can
                                  May 5 '12 at 0:56
















                                179














                                FYI: I've gotten this to work by modifying the tableHeaderView and re-setting it. In this case, i'm adjusting the size of the tableHeaderView when the UIWebView subview has finished loading.



                                [webView sizeToFit];
                                CGRect newFrame = headerView.frame;
                                newFrame.size.height = newFrame.size.height + webView.frame.size.height;
                                headerView.frame = newFrame;
                                [self.tableView setTableHeaderView:headerView];





                                share|improve this answer



















                                • 13





                                  +1 This worked for me. Calling 'setTableHeaderView' after your subview has changed size is the key. The problem is, my subview changes size over a second as an animation. Now I'm trying to figure out how to animate the tableHeaderView with it.

                                  – Andrew
                                  Jan 18 '10 at 7:56






                                • 1





                                  Perfect, thanks a bunch. To me, this is an example of one of the less desirable qualities of properties in Objective-C. There's no way for us to know (and no reason we should know) that setting the header has the side effect of recalculating the height. It should either do it automatically when we update the header's height, or we should be required to call something like [tableView recalculateHeaderHeight] every time.

                                  – jakeboxer
                                  Dec 1 '10 at 17:05








                                • 48





                                  @Andrew I know this is almost a year too late, but better late then never: I was able to animate the changing height of the table header view by wrapping the setTableHeaderView: call with [tableview beginUpdates] and [tableview endUpdates]

                                  – jasongregori
                                  Nov 15 '11 at 1:10








                                • 2





                                  @jasongregori handy comment you added - i'm seeing that the same technique (beginUpdates+endUpdates) does not animate the height change for a tableFooterView the way it does a tableHeaderView. Have you figured out a good way to animate the tableFooterView as well?

                                  – kris
                                  Dec 5 '11 at 23:32






                                • 1





                                  Impressive, it event works when doing it inside a UIView animation block, although I don't think it's very efficient in that case.

                                  – Can
                                  May 5 '12 at 0:56














                                179












                                179








                                179







                                FYI: I've gotten this to work by modifying the tableHeaderView and re-setting it. In this case, i'm adjusting the size of the tableHeaderView when the UIWebView subview has finished loading.



                                [webView sizeToFit];
                                CGRect newFrame = headerView.frame;
                                newFrame.size.height = newFrame.size.height + webView.frame.size.height;
                                headerView.frame = newFrame;
                                [self.tableView setTableHeaderView:headerView];





                                share|improve this answer













                                FYI: I've gotten this to work by modifying the tableHeaderView and re-setting it. In this case, i'm adjusting the size of the tableHeaderView when the UIWebView subview has finished loading.



                                [webView sizeToFit];
                                CGRect newFrame = headerView.frame;
                                newFrame.size.height = newFrame.size.height + webView.frame.size.height;
                                headerView.frame = newFrame;
                                [self.tableView setTableHeaderView:headerView];






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Feb 9 '09 at 1:01









                                kubikubi

                                34.2k1886115




                                34.2k1886115








                                • 13





                                  +1 This worked for me. Calling 'setTableHeaderView' after your subview has changed size is the key. The problem is, my subview changes size over a second as an animation. Now I'm trying to figure out how to animate the tableHeaderView with it.

                                  – Andrew
                                  Jan 18 '10 at 7:56






                                • 1





                                  Perfect, thanks a bunch. To me, this is an example of one of the less desirable qualities of properties in Objective-C. There's no way for us to know (and no reason we should know) that setting the header has the side effect of recalculating the height. It should either do it automatically when we update the header's height, or we should be required to call something like [tableView recalculateHeaderHeight] every time.

                                  – jakeboxer
                                  Dec 1 '10 at 17:05








                                • 48





                                  @Andrew I know this is almost a year too late, but better late then never: I was able to animate the changing height of the table header view by wrapping the setTableHeaderView: call with [tableview beginUpdates] and [tableview endUpdates]

                                  – jasongregori
                                  Nov 15 '11 at 1:10








                                • 2





                                  @jasongregori handy comment you added - i'm seeing that the same technique (beginUpdates+endUpdates) does not animate the height change for a tableFooterView the way it does a tableHeaderView. Have you figured out a good way to animate the tableFooterView as well?

                                  – kris
                                  Dec 5 '11 at 23:32






                                • 1





                                  Impressive, it event works when doing it inside a UIView animation block, although I don't think it's very efficient in that case.

                                  – Can
                                  May 5 '12 at 0:56














                                • 13





                                  +1 This worked for me. Calling 'setTableHeaderView' after your subview has changed size is the key. The problem is, my subview changes size over a second as an animation. Now I'm trying to figure out how to animate the tableHeaderView with it.

                                  – Andrew
                                  Jan 18 '10 at 7:56






                                • 1





                                  Perfect, thanks a bunch. To me, this is an example of one of the less desirable qualities of properties in Objective-C. There's no way for us to know (and no reason we should know) that setting the header has the side effect of recalculating the height. It should either do it automatically when we update the header's height, or we should be required to call something like [tableView recalculateHeaderHeight] every time.

                                  – jakeboxer
                                  Dec 1 '10 at 17:05








                                • 48





                                  @Andrew I know this is almost a year too late, but better late then never: I was able to animate the changing height of the table header view by wrapping the setTableHeaderView: call with [tableview beginUpdates] and [tableview endUpdates]

                                  – jasongregori
                                  Nov 15 '11 at 1:10








                                • 2





                                  @jasongregori handy comment you added - i'm seeing that the same technique (beginUpdates+endUpdates) does not animate the height change for a tableFooterView the way it does a tableHeaderView. Have you figured out a good way to animate the tableFooterView as well?

                                  – kris
                                  Dec 5 '11 at 23:32






                                • 1





                                  Impressive, it event works when doing it inside a UIView animation block, although I don't think it's very efficient in that case.

                                  – Can
                                  May 5 '12 at 0:56








                                13




                                13





                                +1 This worked for me. Calling 'setTableHeaderView' after your subview has changed size is the key. The problem is, my subview changes size over a second as an animation. Now I'm trying to figure out how to animate the tableHeaderView with it.

                                – Andrew
                                Jan 18 '10 at 7:56





                                +1 This worked for me. Calling 'setTableHeaderView' after your subview has changed size is the key. The problem is, my subview changes size over a second as an animation. Now I'm trying to figure out how to animate the tableHeaderView with it.

                                – Andrew
                                Jan 18 '10 at 7:56




                                1




                                1





                                Perfect, thanks a bunch. To me, this is an example of one of the less desirable qualities of properties in Objective-C. There's no way for us to know (and no reason we should know) that setting the header has the side effect of recalculating the height. It should either do it automatically when we update the header's height, or we should be required to call something like [tableView recalculateHeaderHeight] every time.

                                – jakeboxer
                                Dec 1 '10 at 17:05







                                Perfect, thanks a bunch. To me, this is an example of one of the less desirable qualities of properties in Objective-C. There's no way for us to know (and no reason we should know) that setting the header has the side effect of recalculating the height. It should either do it automatically when we update the header's height, or we should be required to call something like [tableView recalculateHeaderHeight] every time.

                                – jakeboxer
                                Dec 1 '10 at 17:05






                                48




                                48





                                @Andrew I know this is almost a year too late, but better late then never: I was able to animate the changing height of the table header view by wrapping the setTableHeaderView: call with [tableview beginUpdates] and [tableview endUpdates]

                                – jasongregori
                                Nov 15 '11 at 1:10







                                @Andrew I know this is almost a year too late, but better late then never: I was able to animate the changing height of the table header view by wrapping the setTableHeaderView: call with [tableview beginUpdates] and [tableview endUpdates]

                                – jasongregori
                                Nov 15 '11 at 1:10






                                2




                                2





                                @jasongregori handy comment you added - i'm seeing that the same technique (beginUpdates+endUpdates) does not animate the height change for a tableFooterView the way it does a tableHeaderView. Have you figured out a good way to animate the tableFooterView as well?

                                – kris
                                Dec 5 '11 at 23:32





                                @jasongregori handy comment you added - i'm seeing that the same technique (beginUpdates+endUpdates) does not animate the height change for a tableFooterView the way it does a tableHeaderView. Have you figured out a good way to animate the tableFooterView as well?

                                – kris
                                Dec 5 '11 at 23:32




                                1




                                1





                                Impressive, it event works when doing it inside a UIView animation block, although I don't think it's very efficient in that case.

                                – Can
                                May 5 '12 at 0:56





                                Impressive, it event works when doing it inside a UIView animation block, although I don't think it's very efficient in that case.

                                – Can
                                May 5 '12 at 0:56













                                12














                                This answer is old and apparently doesn't work on iOS 7 and above.



                                I ran into the same problem, and I also wanted the changes to animate, so I made a subclass of UIView for my header view and added these methods:



                                - (void)adjustTableHeaderHeight:(NSUInteger)newHeight{
                                NSUInteger oldHeight = self.frame.size.height;
                                NSInteger originChange = oldHeight - newHeight;

                                [UIView beginAnimations:nil context:nil];

                                [UIView setAnimationDuration:1.0f];
                                [UIView setAnimationDelegate:self];
                                [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

                                self.frame = CGRectMake(self.frame.origin.x,
                                self.frame.origin.y,
                                self.frame.size.width,
                                newHeight);

                                for (UIView *view in [(UITableView *)self.superview subviews]) {
                                if ([view isKindOfClass:[self class]]) {
                                continue;
                                }
                                view.frame = CGRectMake(view.frame.origin.x,
                                view.frame.origin.y - originChange,
                                view.frame.size.width,
                                view.frame.size.height);
                                }

                                [UIView commitAnimations];
                                }

                                - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
                                [(UITableView *)self.superview setTableHeaderView:self];
                                }


                                This essentially animates all the subviews of the UITableView that aren't the same class type as the calling class. At the end of the animation, it calls setTableHeaderView on the superview (the UITableView) – without this the UITableView contents will jump back the next time the user scrolls. The only limitation I've found on this so far is if the user attempts to scroll the UITableView while the animation is taking place, the scrolling will animate as if the header view hasn't been resized (not a big deal if the animation is quick).






                                share|improve this answer


























                                • works perfectly, removed the animation because I didn't need it.

                                  – Jiho Kang
                                  May 21 '12 at 13:18











                                • Worked perfect until iOS7 happend... added my solution below

                                  – avishic
                                  Sep 24 '13 at 15:54






                                • 1





                                  WTF? You're messing so much with the internals of UITableView that you really shouldn't be surprised that it doesn't work in newer iOS versions... ;)

                                  – Daniel Rinser
                                  Mar 27 '14 at 9:07
















                                12














                                This answer is old and apparently doesn't work on iOS 7 and above.



                                I ran into the same problem, and I also wanted the changes to animate, so I made a subclass of UIView for my header view and added these methods:



                                - (void)adjustTableHeaderHeight:(NSUInteger)newHeight{
                                NSUInteger oldHeight = self.frame.size.height;
                                NSInteger originChange = oldHeight - newHeight;

                                [UIView beginAnimations:nil context:nil];

                                [UIView setAnimationDuration:1.0f];
                                [UIView setAnimationDelegate:self];
                                [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

                                self.frame = CGRectMake(self.frame.origin.x,
                                self.frame.origin.y,
                                self.frame.size.width,
                                newHeight);

                                for (UIView *view in [(UITableView *)self.superview subviews]) {
                                if ([view isKindOfClass:[self class]]) {
                                continue;
                                }
                                view.frame = CGRectMake(view.frame.origin.x,
                                view.frame.origin.y - originChange,
                                view.frame.size.width,
                                view.frame.size.height);
                                }

                                [UIView commitAnimations];
                                }

                                - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
                                [(UITableView *)self.superview setTableHeaderView:self];
                                }


                                This essentially animates all the subviews of the UITableView that aren't the same class type as the calling class. At the end of the animation, it calls setTableHeaderView on the superview (the UITableView) – without this the UITableView contents will jump back the next time the user scrolls. The only limitation I've found on this so far is if the user attempts to scroll the UITableView while the animation is taking place, the scrolling will animate as if the header view hasn't been resized (not a big deal if the animation is quick).






                                share|improve this answer


























                                • works perfectly, removed the animation because I didn't need it.

                                  – Jiho Kang
                                  May 21 '12 at 13:18











                                • Worked perfect until iOS7 happend... added my solution below

                                  – avishic
                                  Sep 24 '13 at 15:54






                                • 1





                                  WTF? You're messing so much with the internals of UITableView that you really shouldn't be surprised that it doesn't work in newer iOS versions... ;)

                                  – Daniel Rinser
                                  Mar 27 '14 at 9:07














                                12












                                12








                                12







                                This answer is old and apparently doesn't work on iOS 7 and above.



                                I ran into the same problem, and I also wanted the changes to animate, so I made a subclass of UIView for my header view and added these methods:



                                - (void)adjustTableHeaderHeight:(NSUInteger)newHeight{
                                NSUInteger oldHeight = self.frame.size.height;
                                NSInteger originChange = oldHeight - newHeight;

                                [UIView beginAnimations:nil context:nil];

                                [UIView setAnimationDuration:1.0f];
                                [UIView setAnimationDelegate:self];
                                [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

                                self.frame = CGRectMake(self.frame.origin.x,
                                self.frame.origin.y,
                                self.frame.size.width,
                                newHeight);

                                for (UIView *view in [(UITableView *)self.superview subviews]) {
                                if ([view isKindOfClass:[self class]]) {
                                continue;
                                }
                                view.frame = CGRectMake(view.frame.origin.x,
                                view.frame.origin.y - originChange,
                                view.frame.size.width,
                                view.frame.size.height);
                                }

                                [UIView commitAnimations];
                                }

                                - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
                                [(UITableView *)self.superview setTableHeaderView:self];
                                }


                                This essentially animates all the subviews of the UITableView that aren't the same class type as the calling class. At the end of the animation, it calls setTableHeaderView on the superview (the UITableView) – without this the UITableView contents will jump back the next time the user scrolls. The only limitation I've found on this so far is if the user attempts to scroll the UITableView while the animation is taking place, the scrolling will animate as if the header view hasn't been resized (not a big deal if the animation is quick).






                                share|improve this answer















                                This answer is old and apparently doesn't work on iOS 7 and above.



                                I ran into the same problem, and I also wanted the changes to animate, so I made a subclass of UIView for my header view and added these methods:



                                - (void)adjustTableHeaderHeight:(NSUInteger)newHeight{
                                NSUInteger oldHeight = self.frame.size.height;
                                NSInteger originChange = oldHeight - newHeight;

                                [UIView beginAnimations:nil context:nil];

                                [UIView setAnimationDuration:1.0f];
                                [UIView setAnimationDelegate:self];
                                [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

                                self.frame = CGRectMake(self.frame.origin.x,
                                self.frame.origin.y,
                                self.frame.size.width,
                                newHeight);

                                for (UIView *view in [(UITableView *)self.superview subviews]) {
                                if ([view isKindOfClass:[self class]]) {
                                continue;
                                }
                                view.frame = CGRectMake(view.frame.origin.x,
                                view.frame.origin.y - originChange,
                                view.frame.size.width,
                                view.frame.size.height);
                                }

                                [UIView commitAnimations];
                                }

                                - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
                                [(UITableView *)self.superview setTableHeaderView:self];
                                }


                                This essentially animates all the subviews of the UITableView that aren't the same class type as the calling class. At the end of the animation, it calls setTableHeaderView on the superview (the UITableView) – without this the UITableView contents will jump back the next time the user scrolls. The only limitation I've found on this so far is if the user attempts to scroll the UITableView while the animation is taking place, the scrolling will animate as if the header view hasn't been resized (not a big deal if the animation is quick).







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Oct 4 '14 at 19:05

























                                answered Feb 1 '10 at 18:42









                                garrettmoongarrettmoon

                                119111




                                119111













                                • works perfectly, removed the animation because I didn't need it.

                                  – Jiho Kang
                                  May 21 '12 at 13:18











                                • Worked perfect until iOS7 happend... added my solution below

                                  – avishic
                                  Sep 24 '13 at 15:54






                                • 1





                                  WTF? You're messing so much with the internals of UITableView that you really shouldn't be surprised that it doesn't work in newer iOS versions... ;)

                                  – Daniel Rinser
                                  Mar 27 '14 at 9:07



















                                • works perfectly, removed the animation because I didn't need it.

                                  – Jiho Kang
                                  May 21 '12 at 13:18











                                • Worked perfect until iOS7 happend... added my solution below

                                  – avishic
                                  Sep 24 '13 at 15:54






                                • 1





                                  WTF? You're messing so much with the internals of UITableView that you really shouldn't be surprised that it doesn't work in newer iOS versions... ;)

                                  – Daniel Rinser
                                  Mar 27 '14 at 9:07

















                                works perfectly, removed the animation because I didn't need it.

                                – Jiho Kang
                                May 21 '12 at 13:18





                                works perfectly, removed the animation because I didn't need it.

                                – Jiho Kang
                                May 21 '12 at 13:18













                                Worked perfect until iOS7 happend... added my solution below

                                – avishic
                                Sep 24 '13 at 15:54





                                Worked perfect until iOS7 happend... added my solution below

                                – avishic
                                Sep 24 '13 at 15:54




                                1




                                1





                                WTF? You're messing so much with the internals of UITableView that you really shouldn't be surprised that it doesn't work in newer iOS versions... ;)

                                – Daniel Rinser
                                Mar 27 '14 at 9:07





                                WTF? You're messing so much with the internals of UITableView that you really shouldn't be surprised that it doesn't work in newer iOS versions... ;)

                                – Daniel Rinser
                                Mar 27 '14 at 9:07











                                10














                                If you want to conditionally animate the changes you can do the following:



                                - (void) showHeader:(BOOL)show animated:(BOOL)animated{

                                CGRect closedFrame = CGRectMake(0, 0, self.view.frame.size.width, 0);
                                CGRect newFrame = show?self.initialFrame:closedFrame;

                                if(animated){
                                // The UIView animation block handles the animation of our header view
                                [UIView beginAnimations:nil context:nil];
                                [UIView setAnimationDuration:0.3];
                                [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

                                // beginUpdates and endUpdates trigger the animation of our cells
                                [self.tableView beginUpdates];
                                }

                                self.headerView.frame = newFrame;
                                [self.tableView setTableHeaderView:self.headerView];

                                if(animated){
                                [self.tableView endUpdates];
                                [UIView commitAnimations];
                                }
                                }


                                Please note that the animation is two-folded:




                                1. The animation of the cells below the tableHeaderView. This is done using beginUpdates and endUpdates

                                2. The animation of the actual header view. This is done using a UIView animation block.


                                In order to synchronize those two animations the animationCurve has to be set to UIViewAnimationCurveEaseInOut and the duration to 0.3, which seems to be what the UITableView uses for it's animation.



                                Update



                                I created an Xcode project on gihub, which does this.
                                Check out the project ResizeTableHeaderViewAnimated in besi/ios-quickies



                                screenshot






                                share|improve this answer





















                                • 2





                                  This technique does work, but it doesn't work for table views with section headers. When you use begin updates/end updates it interferes with the animation block, leaving duplicate section headers.

                                  – BlueFish
                                  Aug 15 '13 at 0:27
















                                10














                                If you want to conditionally animate the changes you can do the following:



                                - (void) showHeader:(BOOL)show animated:(BOOL)animated{

                                CGRect closedFrame = CGRectMake(0, 0, self.view.frame.size.width, 0);
                                CGRect newFrame = show?self.initialFrame:closedFrame;

                                if(animated){
                                // The UIView animation block handles the animation of our header view
                                [UIView beginAnimations:nil context:nil];
                                [UIView setAnimationDuration:0.3];
                                [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

                                // beginUpdates and endUpdates trigger the animation of our cells
                                [self.tableView beginUpdates];
                                }

                                self.headerView.frame = newFrame;
                                [self.tableView setTableHeaderView:self.headerView];

                                if(animated){
                                [self.tableView endUpdates];
                                [UIView commitAnimations];
                                }
                                }


                                Please note that the animation is two-folded:




                                1. The animation of the cells below the tableHeaderView. This is done using beginUpdates and endUpdates

                                2. The animation of the actual header view. This is done using a UIView animation block.


                                In order to synchronize those two animations the animationCurve has to be set to UIViewAnimationCurveEaseInOut and the duration to 0.3, which seems to be what the UITableView uses for it's animation.



                                Update



                                I created an Xcode project on gihub, which does this.
                                Check out the project ResizeTableHeaderViewAnimated in besi/ios-quickies



                                screenshot






                                share|improve this answer





















                                • 2





                                  This technique does work, but it doesn't work for table views with section headers. When you use begin updates/end updates it interferes with the animation block, leaving duplicate section headers.

                                  – BlueFish
                                  Aug 15 '13 at 0:27














                                10












                                10








                                10







                                If you want to conditionally animate the changes you can do the following:



                                - (void) showHeader:(BOOL)show animated:(BOOL)animated{

                                CGRect closedFrame = CGRectMake(0, 0, self.view.frame.size.width, 0);
                                CGRect newFrame = show?self.initialFrame:closedFrame;

                                if(animated){
                                // The UIView animation block handles the animation of our header view
                                [UIView beginAnimations:nil context:nil];
                                [UIView setAnimationDuration:0.3];
                                [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

                                // beginUpdates and endUpdates trigger the animation of our cells
                                [self.tableView beginUpdates];
                                }

                                self.headerView.frame = newFrame;
                                [self.tableView setTableHeaderView:self.headerView];

                                if(animated){
                                [self.tableView endUpdates];
                                [UIView commitAnimations];
                                }
                                }


                                Please note that the animation is two-folded:




                                1. The animation of the cells below the tableHeaderView. This is done using beginUpdates and endUpdates

                                2. The animation of the actual header view. This is done using a UIView animation block.


                                In order to synchronize those two animations the animationCurve has to be set to UIViewAnimationCurveEaseInOut and the duration to 0.3, which seems to be what the UITableView uses for it's animation.



                                Update



                                I created an Xcode project on gihub, which does this.
                                Check out the project ResizeTableHeaderViewAnimated in besi/ios-quickies



                                screenshot






                                share|improve this answer















                                If you want to conditionally animate the changes you can do the following:



                                - (void) showHeader:(BOOL)show animated:(BOOL)animated{

                                CGRect closedFrame = CGRectMake(0, 0, self.view.frame.size.width, 0);
                                CGRect newFrame = show?self.initialFrame:closedFrame;

                                if(animated){
                                // The UIView animation block handles the animation of our header view
                                [UIView beginAnimations:nil context:nil];
                                [UIView setAnimationDuration:0.3];
                                [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

                                // beginUpdates and endUpdates trigger the animation of our cells
                                [self.tableView beginUpdates];
                                }

                                self.headerView.frame = newFrame;
                                [self.tableView setTableHeaderView:self.headerView];

                                if(animated){
                                [self.tableView endUpdates];
                                [UIView commitAnimations];
                                }
                                }


                                Please note that the animation is two-folded:




                                1. The animation of the cells below the tableHeaderView. This is done using beginUpdates and endUpdates

                                2. The animation of the actual header view. This is done using a UIView animation block.


                                In order to synchronize those two animations the animationCurve has to be set to UIViewAnimationCurveEaseInOut and the duration to 0.3, which seems to be what the UITableView uses for it's animation.



                                Update



                                I created an Xcode project on gihub, which does this.
                                Check out the project ResizeTableHeaderViewAnimated in besi/ios-quickies



                                screenshot







                                share|improve this answer














                                share|improve this answer



                                share|improve this answer








                                edited Mar 14 '13 at 18:16

























                                answered Mar 14 '13 at 17:30









                                BesiBesi

                                16.5k18108187




                                16.5k18108187








                                • 2





                                  This technique does work, but it doesn't work for table views with section headers. When you use begin updates/end updates it interferes with the animation block, leaving duplicate section headers.

                                  – BlueFish
                                  Aug 15 '13 at 0:27














                                • 2





                                  This technique does work, but it doesn't work for table views with section headers. When you use begin updates/end updates it interferes with the animation block, leaving duplicate section headers.

                                  – BlueFish
                                  Aug 15 '13 at 0:27








                                2




                                2





                                This technique does work, but it doesn't work for table views with section headers. When you use begin updates/end updates it interferes with the animation block, leaving duplicate section headers.

                                – BlueFish
                                Aug 15 '13 at 0:27





                                This technique does work, but it doesn't work for table views with section headers. When you use begin updates/end updates it interferes with the animation block, leaving duplicate section headers.

                                – BlueFish
                                Aug 15 '13 at 0:27











                                8














                                I think it should work if you just set the height of myHeaderView like so:



                                CGRect newFrame = myHeaderView.frame;
                                newFrame.size.height = newFrame.size.height + 100;
                                myHeaderView.frame = newFrame;

                                self.tableView.tableHeaderView = myHeaderView;





                                share|improve this answer
























                                • This actually works, but only if used in viewDidLayoutSubviews

                                  – KoCMoHaBTa
                                  Dec 22 '14 at 17:43
















                                8














                                I think it should work if you just set the height of myHeaderView like so:



                                CGRect newFrame = myHeaderView.frame;
                                newFrame.size.height = newFrame.size.height + 100;
                                myHeaderView.frame = newFrame;

                                self.tableView.tableHeaderView = myHeaderView;





                                share|improve this answer
























                                • This actually works, but only if used in viewDidLayoutSubviews

                                  – KoCMoHaBTa
                                  Dec 22 '14 at 17:43














                                8












                                8








                                8







                                I think it should work if you just set the height of myHeaderView like so:



                                CGRect newFrame = myHeaderView.frame;
                                newFrame.size.height = newFrame.size.height + 100;
                                myHeaderView.frame = newFrame;

                                self.tableView.tableHeaderView = myHeaderView;





                                share|improve this answer













                                I think it should work if you just set the height of myHeaderView like so:



                                CGRect newFrame = myHeaderView.frame;
                                newFrame.size.height = newFrame.size.height + 100;
                                myHeaderView.frame = newFrame;

                                self.tableView.tableHeaderView = myHeaderView;






                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jan 7 '09 at 3:40









                                Greg MartinGreg Martin

                                4,12432933




                                4,12432933













                                • This actually works, but only if used in viewDidLayoutSubviews

                                  – KoCMoHaBTa
                                  Dec 22 '14 at 17:43



















                                • This actually works, but only if used in viewDidLayoutSubviews

                                  – KoCMoHaBTa
                                  Dec 22 '14 at 17:43

















                                This actually works, but only if used in viewDidLayoutSubviews

                                – KoCMoHaBTa
                                Dec 22 '14 at 17:43





                                This actually works, but only if used in viewDidLayoutSubviews

                                – KoCMoHaBTa
                                Dec 22 '14 at 17:43











                                6














                                Used @garrettmoon solution above until iOS 7.

                                Here's an updated solution based on @garrettmoon's:



                                - (void)adjustTableHeaderHeight:(NSUInteger)newHeight animated:(BOOL)animated {

                                [UIView beginAnimations:nil context:nil];

                                [UIView setAnimationDuration:[CATransaction animationDuration]];
                                [UIView setAnimationDelegate:self];
                                [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

                                self.frame = CGRectMake(self.frame.origin.x,
                                self.frame.origin.y,
                                self.frame.size.width,
                                newHeight);

                                [(UITableView *)self.superview setTableHeaderView:self];

                                [UIView commitAnimations];
                                }

                                - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
                                [(UITableView *)self.superview setTableHeaderView:self];
                                }





                                share|improve this answer




























                                  6














                                  Used @garrettmoon solution above until iOS 7.

                                  Here's an updated solution based on @garrettmoon's:



                                  - (void)adjustTableHeaderHeight:(NSUInteger)newHeight animated:(BOOL)animated {

                                  [UIView beginAnimations:nil context:nil];

                                  [UIView setAnimationDuration:[CATransaction animationDuration]];
                                  [UIView setAnimationDelegate:self];
                                  [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

                                  self.frame = CGRectMake(self.frame.origin.x,
                                  self.frame.origin.y,
                                  self.frame.size.width,
                                  newHeight);

                                  [(UITableView *)self.superview setTableHeaderView:self];

                                  [UIView commitAnimations];
                                  }

                                  - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
                                  [(UITableView *)self.superview setTableHeaderView:self];
                                  }





                                  share|improve this answer


























                                    6












                                    6








                                    6







                                    Used @garrettmoon solution above until iOS 7.

                                    Here's an updated solution based on @garrettmoon's:



                                    - (void)adjustTableHeaderHeight:(NSUInteger)newHeight animated:(BOOL)animated {

                                    [UIView beginAnimations:nil context:nil];

                                    [UIView setAnimationDuration:[CATransaction animationDuration]];
                                    [UIView setAnimationDelegate:self];
                                    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

                                    self.frame = CGRectMake(self.frame.origin.x,
                                    self.frame.origin.y,
                                    self.frame.size.width,
                                    newHeight);

                                    [(UITableView *)self.superview setTableHeaderView:self];

                                    [UIView commitAnimations];
                                    }

                                    - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
                                    [(UITableView *)self.superview setTableHeaderView:self];
                                    }





                                    share|improve this answer













                                    Used @garrettmoon solution above until iOS 7.

                                    Here's an updated solution based on @garrettmoon's:



                                    - (void)adjustTableHeaderHeight:(NSUInteger)newHeight animated:(BOOL)animated {

                                    [UIView beginAnimations:nil context:nil];

                                    [UIView setAnimationDuration:[CATransaction animationDuration]];
                                    [UIView setAnimationDelegate:self];
                                    [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];

                                    self.frame = CGRectMake(self.frame.origin.x,
                                    self.frame.origin.y,
                                    self.frame.size.width,
                                    newHeight);

                                    [(UITableView *)self.superview setTableHeaderView:self];

                                    [UIView commitAnimations];
                                    }

                                    - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context{
                                    [(UITableView *)self.superview setTableHeaderView:self];
                                    }






                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Sep 24 '13 at 15:57









                                    avishicavishic

                                    2,00011537




                                    2,00011537























                                        5














                                        This worked for me on iOS 7 and 8. This code is running on the table view controller.



                                        [UIView animateWithDuration:0.3 animations:^{
                                        CGRect oldFrame = self.headerView.frame;
                                        self.headerView.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, oldFrame.size.width, newHeight);
                                        [self.tableView setTableHeaderView:self.headerView];
                                        }];





                                        share|improve this answer
























                                        • Thanks a lot. This works great ! :)

                                          – Hemang
                                          Sep 2 '15 at 9:27
















                                        5














                                        This worked for me on iOS 7 and 8. This code is running on the table view controller.



                                        [UIView animateWithDuration:0.3 animations:^{
                                        CGRect oldFrame = self.headerView.frame;
                                        self.headerView.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, oldFrame.size.width, newHeight);
                                        [self.tableView setTableHeaderView:self.headerView];
                                        }];





                                        share|improve this answer
























                                        • Thanks a lot. This works great ! :)

                                          – Hemang
                                          Sep 2 '15 at 9:27














                                        5












                                        5








                                        5







                                        This worked for me on iOS 7 and 8. This code is running on the table view controller.



                                        [UIView animateWithDuration:0.3 animations:^{
                                        CGRect oldFrame = self.headerView.frame;
                                        self.headerView.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, oldFrame.size.width, newHeight);
                                        [self.tableView setTableHeaderView:self.headerView];
                                        }];





                                        share|improve this answer













                                        This worked for me on iOS 7 and 8. This code is running on the table view controller.



                                        [UIView animateWithDuration:0.3 animations:^{
                                        CGRect oldFrame = self.headerView.frame;
                                        self.headerView.frame = CGRectMake(oldFrame.origin.x, oldFrame.origin.y, oldFrame.size.width, newHeight);
                                        [self.tableView setTableHeaderView:self.headerView];
                                        }];






                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Nov 27 '14 at 0:29









                                        Darcy RaynerDarcy Rayner

                                        2,75011615




                                        2,75011615













                                        • Thanks a lot. This works great ! :)

                                          – Hemang
                                          Sep 2 '15 at 9:27



















                                        • Thanks a lot. This works great ! :)

                                          – Hemang
                                          Sep 2 '15 at 9:27

















                                        Thanks a lot. This works great ! :)

                                        – Hemang
                                        Sep 2 '15 at 9:27





                                        Thanks a lot. This works great ! :)

                                        – Hemang
                                        Sep 2 '15 at 9:27











                                        4














                                        Its because the setter of tableHeaderView.



                                        You have to set the UIView height before set the tableHeaderView. (Would be much easier if Apple open sources this framework...)






                                        share|improve this answer




























                                          4














                                          Its because the setter of tableHeaderView.



                                          You have to set the UIView height before set the tableHeaderView. (Would be much easier if Apple open sources this framework...)






                                          share|improve this answer


























                                            4












                                            4








                                            4







                                            Its because the setter of tableHeaderView.



                                            You have to set the UIView height before set the tableHeaderView. (Would be much easier if Apple open sources this framework...)






                                            share|improve this answer













                                            Its because the setter of tableHeaderView.



                                            You have to set the UIView height before set the tableHeaderView. (Would be much easier if Apple open sources this framework...)







                                            share|improve this answer












                                            share|improve this answer



                                            share|improve this answer










                                            answered Sep 19 '10 at 21:08









                                            Thomas DecauxThomas Decaux

                                            13.4k25864




                                            13.4k25864























                                                3














                                                On iOS 9 and below, tableHeaderView would not re-layout after resizing it.
                                                This issue is resolved in iOS 10.



                                                To solve this issue, just do it with the following code:



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





                                                share|improve this answer




























                                                  3














                                                  On iOS 9 and below, tableHeaderView would not re-layout after resizing it.
                                                  This issue is resolved in iOS 10.



                                                  To solve this issue, just do it with the following code:



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





                                                  share|improve this answer


























                                                    3












                                                    3








                                                    3







                                                    On iOS 9 and below, tableHeaderView would not re-layout after resizing it.
                                                    This issue is resolved in iOS 10.



                                                    To solve this issue, just do it with the following code:



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





                                                    share|improve this answer













                                                    On iOS 9 and below, tableHeaderView would not re-layout after resizing it.
                                                    This issue is resolved in iOS 10.



                                                    To solve this issue, just do it with the following code:



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






                                                    share|improve this answer












                                                    share|improve this answer



                                                    share|improve this answer










                                                    answered Jan 23 '17 at 12:37









                                                    klaudzklaudz

                                                    26014




                                                    26014























                                                        2














                                                        On iOS 9.x, doing this on viewDidLoad works just fine:



                                                        var frame = headerView.frame
                                                        frame.size.height = 11 // New size
                                                        headerView.frame = frame


                                                        headerView is declared as @IBOutlet var headerView: UIView! and connected on the storyboard, where it is placed at the top of the tableView, to function as the tableHeaderView.






                                                        share|improve this answer






























                                                          2














                                                          On iOS 9.x, doing this on viewDidLoad works just fine:



                                                          var frame = headerView.frame
                                                          frame.size.height = 11 // New size
                                                          headerView.frame = frame


                                                          headerView is declared as @IBOutlet var headerView: UIView! and connected on the storyboard, where it is placed at the top of the tableView, to function as the tableHeaderView.






                                                          share|improve this answer




























                                                            2












                                                            2








                                                            2







                                                            On iOS 9.x, doing this on viewDidLoad works just fine:



                                                            var frame = headerView.frame
                                                            frame.size.height = 11 // New size
                                                            headerView.frame = frame


                                                            headerView is declared as @IBOutlet var headerView: UIView! and connected on the storyboard, where it is placed at the top of the tableView, to function as the tableHeaderView.






                                                            share|improve this answer















                                                            On iOS 9.x, doing this on viewDidLoad works just fine:



                                                            var frame = headerView.frame
                                                            frame.size.height = 11 // New size
                                                            headerView.frame = frame


                                                            headerView is declared as @IBOutlet var headerView: UIView! and connected on the storyboard, where it is placed at the top of the tableView, to function as the tableHeaderView.







                                                            share|improve this answer














                                                            share|improve this answer



                                                            share|improve this answer








                                                            edited Apr 2 '17 at 2:47









                                                            Harris

                                                            4,86413841




                                                            4,86413841










                                                            answered Jun 6 '16 at 17:31









                                                            Eneko AlonsoEneko Alonso

                                                            12.1k53757




                                                            12.1k53757























                                                                1














                                                                Setting the height for header view property tableView.tableHeaderView in viewDidLoad seems not work, the header view height still not change as expected.



                                                                After fighting against this issue for many tries. I found that, you can change the height by invoking the header view create logic inside the
                                                                - (void)didMoveToParentViewController:(UIViewController *)parent method.



                                                                So the example code would look like this:



                                                                - (void)didMoveToParentViewController:(UIViewController *)parent {
                                                                [super didMoveToParentViewController:parent];

                                                                if ( _tableView.tableHeaderView == nil ) {
                                                                UIView *header = [[[UINib nibWithNibName:@"your header view" bundle:nil] instantiateWithOwner:self options:nil] firstObject];

                                                                header.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), HeaderViewHeight);

                                                                [_tableView setTableHeaderView:header];
                                                                }
                                                                }





                                                                share|improve this answer




























                                                                  1














                                                                  Setting the height for header view property tableView.tableHeaderView in viewDidLoad seems not work, the header view height still not change as expected.



                                                                  After fighting against this issue for many tries. I found that, you can change the height by invoking the header view create logic inside the
                                                                  - (void)didMoveToParentViewController:(UIViewController *)parent method.



                                                                  So the example code would look like this:



                                                                  - (void)didMoveToParentViewController:(UIViewController *)parent {
                                                                  [super didMoveToParentViewController:parent];

                                                                  if ( _tableView.tableHeaderView == nil ) {
                                                                  UIView *header = [[[UINib nibWithNibName:@"your header view" bundle:nil] instantiateWithOwner:self options:nil] firstObject];

                                                                  header.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), HeaderViewHeight);

                                                                  [_tableView setTableHeaderView:header];
                                                                  }
                                                                  }





                                                                  share|improve this answer


























                                                                    1












                                                                    1








                                                                    1







                                                                    Setting the height for header view property tableView.tableHeaderView in viewDidLoad seems not work, the header view height still not change as expected.



                                                                    After fighting against this issue for many tries. I found that, you can change the height by invoking the header view create logic inside the
                                                                    - (void)didMoveToParentViewController:(UIViewController *)parent method.



                                                                    So the example code would look like this:



                                                                    - (void)didMoveToParentViewController:(UIViewController *)parent {
                                                                    [super didMoveToParentViewController:parent];

                                                                    if ( _tableView.tableHeaderView == nil ) {
                                                                    UIView *header = [[[UINib nibWithNibName:@"your header view" bundle:nil] instantiateWithOwner:self options:nil] firstObject];

                                                                    header.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), HeaderViewHeight);

                                                                    [_tableView setTableHeaderView:header];
                                                                    }
                                                                    }





                                                                    share|improve this answer













                                                                    Setting the height for header view property tableView.tableHeaderView in viewDidLoad seems not work, the header view height still not change as expected.



                                                                    After fighting against this issue for many tries. I found that, you can change the height by invoking the header view create logic inside the
                                                                    - (void)didMoveToParentViewController:(UIViewController *)parent method.



                                                                    So the example code would look like this:



                                                                    - (void)didMoveToParentViewController:(UIViewController *)parent {
                                                                    [super didMoveToParentViewController:parent];

                                                                    if ( _tableView.tableHeaderView == nil ) {
                                                                    UIView *header = [[[UINib nibWithNibName:@"your header view" bundle:nil] instantiateWithOwner:self options:nil] firstObject];

                                                                    header.frame = CGRectMake(0, 0, CGRectGetWidth([UIScreen mainScreen].bounds), HeaderViewHeight);

                                                                    [_tableView setTableHeaderView:header];
                                                                    }
                                                                    }






                                                                    share|improve this answer












                                                                    share|improve this answer



                                                                    share|improve this answer










                                                                    answered Jan 20 '17 at 2:51









                                                                    EnixEnix

                                                                    2,1931522




                                                                    2,1931522























                                                                        0














                                                                        I found the initWithFrame initializer of a UIView doesn't properly honor the rect I pass in. Hence, I did the following which worked perfectly:



                                                                         - (id)initWithFrame:(CGRect)aRect {

                                                                        CGRect frame = [[UIScreen mainScreen] applicationFrame];

                                                                        if ((self = [super initWithFrame:CGRectZero])) {

                                                                        // Ugly initialization behavior - initWithFrame will not properly honor the frame we pass
                                                                        self.frame = CGRectMake(0, 0, frame.size.width, 200);

                                                                        // ...
                                                                        }
                                                                        }


                                                                        The advantage of this is it is better encapsulated into your view code.






                                                                        share|improve this answer
























                                                                        • Fetching the frame from UIScreen is a bad idea, how will you re-use your view?

                                                                          – Zorayr
                                                                          Apr 14 '16 at 19:44
















                                                                        0














                                                                        I found the initWithFrame initializer of a UIView doesn't properly honor the rect I pass in. Hence, I did the following which worked perfectly:



                                                                         - (id)initWithFrame:(CGRect)aRect {

                                                                        CGRect frame = [[UIScreen mainScreen] applicationFrame];

                                                                        if ((self = [super initWithFrame:CGRectZero])) {

                                                                        // Ugly initialization behavior - initWithFrame will not properly honor the frame we pass
                                                                        self.frame = CGRectMake(0, 0, frame.size.width, 200);

                                                                        // ...
                                                                        }
                                                                        }


                                                                        The advantage of this is it is better encapsulated into your view code.






                                                                        share|improve this answer
























                                                                        • Fetching the frame from UIScreen is a bad idea, how will you re-use your view?

                                                                          – Zorayr
                                                                          Apr 14 '16 at 19:44














                                                                        0












                                                                        0








                                                                        0







                                                                        I found the initWithFrame initializer of a UIView doesn't properly honor the rect I pass in. Hence, I did the following which worked perfectly:



                                                                         - (id)initWithFrame:(CGRect)aRect {

                                                                        CGRect frame = [[UIScreen mainScreen] applicationFrame];

                                                                        if ((self = [super initWithFrame:CGRectZero])) {

                                                                        // Ugly initialization behavior - initWithFrame will not properly honor the frame we pass
                                                                        self.frame = CGRectMake(0, 0, frame.size.width, 200);

                                                                        // ...
                                                                        }
                                                                        }


                                                                        The advantage of this is it is better encapsulated into your view code.






                                                                        share|improve this answer













                                                                        I found the initWithFrame initializer of a UIView doesn't properly honor the rect I pass in. Hence, I did the following which worked perfectly:



                                                                         - (id)initWithFrame:(CGRect)aRect {

                                                                        CGRect frame = [[UIScreen mainScreen] applicationFrame];

                                                                        if ((self = [super initWithFrame:CGRectZero])) {

                                                                        // Ugly initialization behavior - initWithFrame will not properly honor the frame we pass
                                                                        self.frame = CGRectMake(0, 0, frame.size.width, 200);

                                                                        // ...
                                                                        }
                                                                        }


                                                                        The advantage of this is it is better encapsulated into your view code.







                                                                        share|improve this answer












                                                                        share|improve this answer



                                                                        share|improve this answer










                                                                        answered Dec 5 '10 at 16:34









                                                                        Harald SchubertHarald Schubert

                                                                        91




                                                                        91













                                                                        • Fetching the frame from UIScreen is a bad idea, how will you re-use your view?

                                                                          – Zorayr
                                                                          Apr 14 '16 at 19:44



















                                                                        • Fetching the frame from UIScreen is a bad idea, how will you re-use your view?

                                                                          – Zorayr
                                                                          Apr 14 '16 at 19:44

















                                                                        Fetching the frame from UIScreen is a bad idea, how will you re-use your view?

                                                                        – Zorayr
                                                                        Apr 14 '16 at 19:44





                                                                        Fetching the frame from UIScreen is a bad idea, how will you re-use your view?

                                                                        – Zorayr
                                                                        Apr 14 '16 at 19:44











                                                                        0














                                                                        I have implemented animated height change of the table's header to expand to overall screen when tapped. However, the code can help in other cases:



                                                                        // Swift
                                                                        @IBAction func tapped(sender: UITapGestureRecognizer) {

                                                                        self.tableView.beginUpdates() // Required to update cells.

                                                                        // Collapse table header to original height
                                                                        if isHeaderExpandedToFullScreen {

                                                                        UIView.animateWithDuration(0.5, animations: { () -> Void in
                                                                        self.scrollView.frame.size.height = 110 // original height in my case is 110
                                                                        })

                                                                        }
                                                                        // Expand table header to overall screen
                                                                        else {
                                                                        let screenSize = self.view.frame // "screen" size

                                                                        UIView.animateWithDuration(0.5, animations: { () -> Void in
                                                                        self.scrollView.frame.size.height = screenSize.height
                                                                        })
                                                                        }

                                                                        self.tableView.endUpdates() // Required to update cells.

                                                                        isHeaderExpandedToFullScreen= !isHeaderExpandedToFullScreen // Toggle
                                                                        }





                                                                        share|improve this answer




























                                                                          0














                                                                          I have implemented animated height change of the table's header to expand to overall screen when tapped. However, the code can help in other cases:



                                                                          // Swift
                                                                          @IBAction func tapped(sender: UITapGestureRecognizer) {

                                                                          self.tableView.beginUpdates() // Required to update cells.

                                                                          // Collapse table header to original height
                                                                          if isHeaderExpandedToFullScreen {

                                                                          UIView.animateWithDuration(0.5, animations: { () -> Void in
                                                                          self.scrollView.frame.size.height = 110 // original height in my case is 110
                                                                          })

                                                                          }
                                                                          // Expand table header to overall screen
                                                                          else {
                                                                          let screenSize = self.view.frame // "screen" size

                                                                          UIView.animateWithDuration(0.5, animations: { () -> Void in
                                                                          self.scrollView.frame.size.height = screenSize.height
                                                                          })
                                                                          }

                                                                          self.tableView.endUpdates() // Required to update cells.

                                                                          isHeaderExpandedToFullScreen= !isHeaderExpandedToFullScreen // Toggle
                                                                          }





                                                                          share|improve this answer


























                                                                            0












                                                                            0








                                                                            0







                                                                            I have implemented animated height change of the table's header to expand to overall screen when tapped. However, the code can help in other cases:



                                                                            // Swift
                                                                            @IBAction func tapped(sender: UITapGestureRecognizer) {

                                                                            self.tableView.beginUpdates() // Required to update cells.

                                                                            // Collapse table header to original height
                                                                            if isHeaderExpandedToFullScreen {

                                                                            UIView.animateWithDuration(0.5, animations: { () -> Void in
                                                                            self.scrollView.frame.size.height = 110 // original height in my case is 110
                                                                            })

                                                                            }
                                                                            // Expand table header to overall screen
                                                                            else {
                                                                            let screenSize = self.view.frame // "screen" size

                                                                            UIView.animateWithDuration(0.5, animations: { () -> Void in
                                                                            self.scrollView.frame.size.height = screenSize.height
                                                                            })
                                                                            }

                                                                            self.tableView.endUpdates() // Required to update cells.

                                                                            isHeaderExpandedToFullScreen= !isHeaderExpandedToFullScreen // Toggle
                                                                            }





                                                                            share|improve this answer













                                                                            I have implemented animated height change of the table's header to expand to overall screen when tapped. However, the code can help in other cases:



                                                                            // Swift
                                                                            @IBAction func tapped(sender: UITapGestureRecognizer) {

                                                                            self.tableView.beginUpdates() // Required to update cells.

                                                                            // Collapse table header to original height
                                                                            if isHeaderExpandedToFullScreen {

                                                                            UIView.animateWithDuration(0.5, animations: { () -> Void in
                                                                            self.scrollView.frame.size.height = 110 // original height in my case is 110
                                                                            })

                                                                            }
                                                                            // Expand table header to overall screen
                                                                            else {
                                                                            let screenSize = self.view.frame // "screen" size

                                                                            UIView.animateWithDuration(0.5, animations: { () -> Void in
                                                                            self.scrollView.frame.size.height = screenSize.height
                                                                            })
                                                                            }

                                                                            self.tableView.endUpdates() // Required to update cells.

                                                                            isHeaderExpandedToFullScreen= !isHeaderExpandedToFullScreen // Toggle
                                                                            }






                                                                            share|improve this answer












                                                                            share|improve this answer



                                                                            share|improve this answer










                                                                            answered Sep 21 '14 at 16:11









                                                                            Alexander VolkovAlexander Volkov

                                                                            5,01113330




                                                                            5,01113330























                                                                                0














                                                                                UITableView resizing header - UISearchBar with Scope Bar



                                                                                I wanted a UITableView with a UISearchBar as the header to the table so I have a hierarchy that looks like this



                                                                                UITableView
                                                                                |
                                                                                |--> UIView
                                                                                | |--> UISearchBar
                                                                                |
                                                                                |--> UITableViewCells


                                                                                UISearchBarDelegate methods



                                                                                As has been stated elsewhere, if you don't setTableViewHeader after changing it, nothing will happen.



                                                                                - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
                                                                                {
                                                                                searchBar.showsScopeBar = YES;
                                                                                [UIView animateWithDuration:0.2f animations:^{
                                                                                [searchBar sizeToFit];
                                                                                CGFloat height = CGRectGetHeight(searchBar.frame);

                                                                                CGRect frame = self.tableView.tableHeaderView.frame;
                                                                                frame.size.height = height;
                                                                                self.tableHeaderView.frame = frame;
                                                                                self.tableView.tableHeaderView = self.tableHeaderView;
                                                                                }];

                                                                                [searchBar setShowsCancelButton:YES animated:YES];
                                                                                return YES;
                                                                                }

                                                                                - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
                                                                                {
                                                                                searchBar.showsScopeBar = NO;
                                                                                [UIView animateWithDuration:0.f animations:^{
                                                                                [searchBar sizeToFit];

                                                                                CGFloat height = CGRectGetHeight(searchBar.frame);

                                                                                CGRect frame = self.tableView.tableHeaderView.frame;
                                                                                frame.size.height = height;
                                                                                self.tableHeaderView.frame = frame;
                                                                                self.tableView.tableHeaderView = self.tableHeaderView;
                                                                                }];

                                                                                [searchBar setShowsCancelButton:NO animated:YES];
                                                                                return YES;
                                                                                }





                                                                                share|improve this answer




























                                                                                  0














                                                                                  UITableView resizing header - UISearchBar with Scope Bar



                                                                                  I wanted a UITableView with a UISearchBar as the header to the table so I have a hierarchy that looks like this



                                                                                  UITableView
                                                                                  |
                                                                                  |--> UIView
                                                                                  | |--> UISearchBar
                                                                                  |
                                                                                  |--> UITableViewCells


                                                                                  UISearchBarDelegate methods



                                                                                  As has been stated elsewhere, if you don't setTableViewHeader after changing it, nothing will happen.



                                                                                  - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
                                                                                  {
                                                                                  searchBar.showsScopeBar = YES;
                                                                                  [UIView animateWithDuration:0.2f animations:^{
                                                                                  [searchBar sizeToFit];
                                                                                  CGFloat height = CGRectGetHeight(searchBar.frame);

                                                                                  CGRect frame = self.tableView.tableHeaderView.frame;
                                                                                  frame.size.height = height;
                                                                                  self.tableHeaderView.frame = frame;
                                                                                  self.tableView.tableHeaderView = self.tableHeaderView;
                                                                                  }];

                                                                                  [searchBar setShowsCancelButton:YES animated:YES];
                                                                                  return YES;
                                                                                  }

                                                                                  - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
                                                                                  {
                                                                                  searchBar.showsScopeBar = NO;
                                                                                  [UIView animateWithDuration:0.f animations:^{
                                                                                  [searchBar sizeToFit];

                                                                                  CGFloat height = CGRectGetHeight(searchBar.frame);

                                                                                  CGRect frame = self.tableView.tableHeaderView.frame;
                                                                                  frame.size.height = height;
                                                                                  self.tableHeaderView.frame = frame;
                                                                                  self.tableView.tableHeaderView = self.tableHeaderView;
                                                                                  }];

                                                                                  [searchBar setShowsCancelButton:NO animated:YES];
                                                                                  return YES;
                                                                                  }





                                                                                  share|improve this answer


























                                                                                    0












                                                                                    0








                                                                                    0







                                                                                    UITableView resizing header - UISearchBar with Scope Bar



                                                                                    I wanted a UITableView with a UISearchBar as the header to the table so I have a hierarchy that looks like this



                                                                                    UITableView
                                                                                    |
                                                                                    |--> UIView
                                                                                    | |--> UISearchBar
                                                                                    |
                                                                                    |--> UITableViewCells


                                                                                    UISearchBarDelegate methods



                                                                                    As has been stated elsewhere, if you don't setTableViewHeader after changing it, nothing will happen.



                                                                                    - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
                                                                                    {
                                                                                    searchBar.showsScopeBar = YES;
                                                                                    [UIView animateWithDuration:0.2f animations:^{
                                                                                    [searchBar sizeToFit];
                                                                                    CGFloat height = CGRectGetHeight(searchBar.frame);

                                                                                    CGRect frame = self.tableView.tableHeaderView.frame;
                                                                                    frame.size.height = height;
                                                                                    self.tableHeaderView.frame = frame;
                                                                                    self.tableView.tableHeaderView = self.tableHeaderView;
                                                                                    }];

                                                                                    [searchBar setShowsCancelButton:YES animated:YES];
                                                                                    return YES;
                                                                                    }

                                                                                    - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
                                                                                    {
                                                                                    searchBar.showsScopeBar = NO;
                                                                                    [UIView animateWithDuration:0.f animations:^{
                                                                                    [searchBar sizeToFit];

                                                                                    CGFloat height = CGRectGetHeight(searchBar.frame);

                                                                                    CGRect frame = self.tableView.tableHeaderView.frame;
                                                                                    frame.size.height = height;
                                                                                    self.tableHeaderView.frame = frame;
                                                                                    self.tableView.tableHeaderView = self.tableHeaderView;
                                                                                    }];

                                                                                    [searchBar setShowsCancelButton:NO animated:YES];
                                                                                    return YES;
                                                                                    }





                                                                                    share|improve this answer













                                                                                    UITableView resizing header - UISearchBar with Scope Bar



                                                                                    I wanted a UITableView with a UISearchBar as the header to the table so I have a hierarchy that looks like this



                                                                                    UITableView
                                                                                    |
                                                                                    |--> UIView
                                                                                    | |--> UISearchBar
                                                                                    |
                                                                                    |--> UITableViewCells


                                                                                    UISearchBarDelegate methods



                                                                                    As has been stated elsewhere, if you don't setTableViewHeader after changing it, nothing will happen.



                                                                                    - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
                                                                                    {
                                                                                    searchBar.showsScopeBar = YES;
                                                                                    [UIView animateWithDuration:0.2f animations:^{
                                                                                    [searchBar sizeToFit];
                                                                                    CGFloat height = CGRectGetHeight(searchBar.frame);

                                                                                    CGRect frame = self.tableView.tableHeaderView.frame;
                                                                                    frame.size.height = height;
                                                                                    self.tableHeaderView.frame = frame;
                                                                                    self.tableView.tableHeaderView = self.tableHeaderView;
                                                                                    }];

                                                                                    [searchBar setShowsCancelButton:YES animated:YES];
                                                                                    return YES;
                                                                                    }

                                                                                    - (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
                                                                                    {
                                                                                    searchBar.showsScopeBar = NO;
                                                                                    [UIView animateWithDuration:0.f animations:^{
                                                                                    [searchBar sizeToFit];

                                                                                    CGFloat height = CGRectGetHeight(searchBar.frame);

                                                                                    CGRect frame = self.tableView.tableHeaderView.frame;
                                                                                    frame.size.height = height;
                                                                                    self.tableHeaderView.frame = frame;
                                                                                    self.tableView.tableHeaderView = self.tableHeaderView;
                                                                                    }];

                                                                                    [searchBar setShowsCancelButton:NO animated:YES];
                                                                                    return YES;
                                                                                    }






                                                                                    share|improve this answer












                                                                                    share|improve this answer



                                                                                    share|improve this answer










                                                                                    answered Jun 6 '15 at 12:23









                                                                                    Cameron Lowell PalmerCameron Lowell Palmer

                                                                                    14.9k48097




                                                                                    14.9k48097























                                                                                        0














                                                                                        If custom headerView is designed using autolayout and headerView needs to be updated after web-fetch or similar lazy task.
                                                                                        then in iOS-Swift I did this and got my headerView updated using bellow code:



                                                                                        //to reload your cell data
                                                                                        self.tableView.reloadData()
                                                                                        dispatch_async(dispatch_get_main_queue(),{
                                                                                        // this is needed to update a specific tableview's headerview layout on main queue otherwise it's won't update perfectly cause reloaddata() is called
                                                                                        self.tableView.beginUpdates()
                                                                                        self.tableView.endUpdates()
                                                                                        }





                                                                                        share|improve this answer




























                                                                                          0














                                                                                          If custom headerView is designed using autolayout and headerView needs to be updated after web-fetch or similar lazy task.
                                                                                          then in iOS-Swift I did this and got my headerView updated using bellow code:



                                                                                          //to reload your cell data
                                                                                          self.tableView.reloadData()
                                                                                          dispatch_async(dispatch_get_main_queue(),{
                                                                                          // this is needed to update a specific tableview's headerview layout on main queue otherwise it's won't update perfectly cause reloaddata() is called
                                                                                          self.tableView.beginUpdates()
                                                                                          self.tableView.endUpdates()
                                                                                          }





                                                                                          share|improve this answer


























                                                                                            0












                                                                                            0








                                                                                            0







                                                                                            If custom headerView is designed using autolayout and headerView needs to be updated after web-fetch or similar lazy task.
                                                                                            then in iOS-Swift I did this and got my headerView updated using bellow code:



                                                                                            //to reload your cell data
                                                                                            self.tableView.reloadData()
                                                                                            dispatch_async(dispatch_get_main_queue(),{
                                                                                            // this is needed to update a specific tableview's headerview layout on main queue otherwise it's won't update perfectly cause reloaddata() is called
                                                                                            self.tableView.beginUpdates()
                                                                                            self.tableView.endUpdates()
                                                                                            }





                                                                                            share|improve this answer













                                                                                            If custom headerView is designed using autolayout and headerView needs to be updated after web-fetch or similar lazy task.
                                                                                            then in iOS-Swift I did this and got my headerView updated using bellow code:



                                                                                            //to reload your cell data
                                                                                            self.tableView.reloadData()
                                                                                            dispatch_async(dispatch_get_main_queue(),{
                                                                                            // this is needed to update a specific tableview's headerview layout on main queue otherwise it's won't update perfectly cause reloaddata() is called
                                                                                            self.tableView.beginUpdates()
                                                                                            self.tableView.endUpdates()
                                                                                            }






                                                                                            share|improve this answer












                                                                                            share|improve this answer



                                                                                            share|improve this answer










                                                                                            answered Jun 6 '16 at 9:19









                                                                                            Rafat touqir RafsunRafat touqir Rafsun

                                                                                            2,2041922




                                                                                            2,2041922























                                                                                                0














                                                                                                Obviously, by now Apple should have implemented UITableViewAutomaticDimension for tableHeaderView & tableFooterView...



                                                                                                The following seems to work for me using layout contraint(s):



                                                                                                CGSize   s  = [ self  systemLayoutSizeFittingSize : UILayoutFittingCompressedSize ];
                                                                                                CGRect f = [ self frame ];

                                                                                                f.size = s;

                                                                                                [ self setFrame : f ];





                                                                                                share|improve this answer




























                                                                                                  0














                                                                                                  Obviously, by now Apple should have implemented UITableViewAutomaticDimension for tableHeaderView & tableFooterView...



                                                                                                  The following seems to work for me using layout contraint(s):



                                                                                                  CGSize   s  = [ self  systemLayoutSizeFittingSize : UILayoutFittingCompressedSize ];
                                                                                                  CGRect f = [ self frame ];

                                                                                                  f.size = s;

                                                                                                  [ self setFrame : f ];





                                                                                                  share|improve this answer


























                                                                                                    0












                                                                                                    0








                                                                                                    0







                                                                                                    Obviously, by now Apple should have implemented UITableViewAutomaticDimension for tableHeaderView & tableFooterView...



                                                                                                    The following seems to work for me using layout contraint(s):



                                                                                                    CGSize   s  = [ self  systemLayoutSizeFittingSize : UILayoutFittingCompressedSize ];
                                                                                                    CGRect f = [ self frame ];

                                                                                                    f.size = s;

                                                                                                    [ self setFrame : f ];





                                                                                                    share|improve this answer













                                                                                                    Obviously, by now Apple should have implemented UITableViewAutomaticDimension for tableHeaderView & tableFooterView...



                                                                                                    The following seems to work for me using layout contraint(s):



                                                                                                    CGSize   s  = [ self  systemLayoutSizeFittingSize : UILayoutFittingCompressedSize ];
                                                                                                    CGRect f = [ self frame ];

                                                                                                    f.size = s;

                                                                                                    [ self setFrame : f ];






                                                                                                    share|improve this answer












                                                                                                    share|improve this answer



                                                                                                    share|improve this answer










                                                                                                    answered Dec 30 '17 at 15:04









                                                                                                    digitaldaemondigitaldaemon

                                                                                                    612




                                                                                                    612























                                                                                                        0














                                                                                                        If your tableHeaderView is a content adjustable webView,you can try:



                                                                                                        [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];

                                                                                                        - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
                                                                                                        self.webView.height = self.webView.scrollView.contentSize.height;
                                                                                                        self.tableView.tableHeaderView = self.webView;
                                                                                                        }


                                                                                                        I tested it on iOS9 and iOS11,worked well.






                                                                                                        share|improve this answer




























                                                                                                          0














                                                                                                          If your tableHeaderView is a content adjustable webView,you can try:



                                                                                                          [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];

                                                                                                          - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
                                                                                                          self.webView.height = self.webView.scrollView.contentSize.height;
                                                                                                          self.tableView.tableHeaderView = self.webView;
                                                                                                          }


                                                                                                          I tested it on iOS9 and iOS11,worked well.






                                                                                                          share|improve this answer


























                                                                                                            0












                                                                                                            0








                                                                                                            0







                                                                                                            If your tableHeaderView is a content adjustable webView,you can try:



                                                                                                            [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];

                                                                                                            - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
                                                                                                            self.webView.height = self.webView.scrollView.contentSize.height;
                                                                                                            self.tableView.tableHeaderView = self.webView;
                                                                                                            }


                                                                                                            I tested it on iOS9 and iOS11,worked well.






                                                                                                            share|improve this answer













                                                                                                            If your tableHeaderView is a content adjustable webView,you can try:



                                                                                                            [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:NSKeyValueObservingOptionNew context:nil];

                                                                                                            - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
                                                                                                            self.webView.height = self.webView.scrollView.contentSize.height;
                                                                                                            self.tableView.tableHeaderView = self.webView;
                                                                                                            }


                                                                                                            I tested it on iOS9 and iOS11,worked well.







                                                                                                            share|improve this answer












                                                                                                            share|improve this answer



                                                                                                            share|improve this answer










                                                                                                            answered Sep 27 '18 at 9:37









                                                                                                            无夜之星辰无夜之星辰

                                                                                                            8391820




                                                                                                            8391820























                                                                                                                0














                                                                                                                This is only for when you use auto-layout and set translatesAutoresizingMaskIntoConstraints = false to a custom header view.



                                                                                                                The best and the simplest way is to override intrinsicContentSize. Internally UITableView uses intrinsicContentSize to decide its header/footer size. Once you have override intrinsicContentSize in your custom view, What you need to do is as below




                                                                                                                1. configure the custom header/footer view's layout(subviews)

                                                                                                                2. invoke invalidateIntrinsicContentSize()

                                                                                                                3. invoke tableView.setNeedsLayout() and tableView.layoutIfNeeded()


                                                                                                                Then the UITableView's header/footer will be updated as you want. No need to set the view nil or reset.



                                                                                                                One thing really interesting for the UITableView.tableHeaderView or .tableFooterView is that UIStackView loose its ability to manage its arrangedSubviews. If you want to use UIStackView as a tableHeaderView or tableFooterView, you have to embed the stackView in a UIView and override UIView's intrinsicContentSize.






                                                                                                                share|improve this answer






























                                                                                                                  0














                                                                                                                  This is only for when you use auto-layout and set translatesAutoresizingMaskIntoConstraints = false to a custom header view.



                                                                                                                  The best and the simplest way is to override intrinsicContentSize. Internally UITableView uses intrinsicContentSize to decide its header/footer size. Once you have override intrinsicContentSize in your custom view, What you need to do is as below




                                                                                                                  1. configure the custom header/footer view's layout(subviews)

                                                                                                                  2. invoke invalidateIntrinsicContentSize()

                                                                                                                  3. invoke tableView.setNeedsLayout() and tableView.layoutIfNeeded()


                                                                                                                  Then the UITableView's header/footer will be updated as you want. No need to set the view nil or reset.



                                                                                                                  One thing really interesting for the UITableView.tableHeaderView or .tableFooterView is that UIStackView loose its ability to manage its arrangedSubviews. If you want to use UIStackView as a tableHeaderView or tableFooterView, you have to embed the stackView in a UIView and override UIView's intrinsicContentSize.






                                                                                                                  share|improve this answer




























                                                                                                                    0












                                                                                                                    0








                                                                                                                    0







                                                                                                                    This is only for when you use auto-layout and set translatesAutoresizingMaskIntoConstraints = false to a custom header view.



                                                                                                                    The best and the simplest way is to override intrinsicContentSize. Internally UITableView uses intrinsicContentSize to decide its header/footer size. Once you have override intrinsicContentSize in your custom view, What you need to do is as below




                                                                                                                    1. configure the custom header/footer view's layout(subviews)

                                                                                                                    2. invoke invalidateIntrinsicContentSize()

                                                                                                                    3. invoke tableView.setNeedsLayout() and tableView.layoutIfNeeded()


                                                                                                                    Then the UITableView's header/footer will be updated as you want. No need to set the view nil or reset.



                                                                                                                    One thing really interesting for the UITableView.tableHeaderView or .tableFooterView is that UIStackView loose its ability to manage its arrangedSubviews. If you want to use UIStackView as a tableHeaderView or tableFooterView, you have to embed the stackView in a UIView and override UIView's intrinsicContentSize.






                                                                                                                    share|improve this answer















                                                                                                                    This is only for when you use auto-layout and set translatesAutoresizingMaskIntoConstraints = false to a custom header view.



                                                                                                                    The best and the simplest way is to override intrinsicContentSize. Internally UITableView uses intrinsicContentSize to decide its header/footer size. Once you have override intrinsicContentSize in your custom view, What you need to do is as below




                                                                                                                    1. configure the custom header/footer view's layout(subviews)

                                                                                                                    2. invoke invalidateIntrinsicContentSize()

                                                                                                                    3. invoke tableView.setNeedsLayout() and tableView.layoutIfNeeded()


                                                                                                                    Then the UITableView's header/footer will be updated as you want. No need to set the view nil or reset.



                                                                                                                    One thing really interesting for the UITableView.tableHeaderView or .tableFooterView is that UIStackView loose its ability to manage its arrangedSubviews. If you want to use UIStackView as a tableHeaderView or tableFooterView, you have to embed the stackView in a UIView and override UIView's intrinsicContentSize.







                                                                                                                    share|improve this answer














                                                                                                                    share|improve this answer



                                                                                                                    share|improve this answer








                                                                                                                    edited Nov 21 '18 at 22:58

























                                                                                                                    answered Nov 21 '18 at 21:45









                                                                                                                    RyanRyan

                                                                                                                    3,4942245




                                                                                                                    3,4942245























                                                                                                                        -3














                                                                                                                        Did you try
                                                                                                                        [self.tableView reloadData] after changing the height?






                                                                                                                        share|improve this answer
























                                                                                                                        • I've tried this but the header didn't resized.

                                                                                                                          – wal
                                                                                                                          Aug 19 '10 at 20:22











                                                                                                                        • didnt work either

                                                                                                                          – khalil
                                                                                                                          Jan 10 '13 at 8:56






                                                                                                                        • 1





                                                                                                                          It's about the tableHeaderView, which is a static view. - [UITableView reloadData] is only intended for the dynamic views (cells) and also the sectionHeaders which you obviously thought were meant ;)

                                                                                                                          – Julian F. Weinert
                                                                                                                          Jul 16 '15 at 11:29
















                                                                                                                        -3














                                                                                                                        Did you try
                                                                                                                        [self.tableView reloadData] after changing the height?






                                                                                                                        share|improve this answer
























                                                                                                                        • I've tried this but the header didn't resized.

                                                                                                                          – wal
                                                                                                                          Aug 19 '10 at 20:22











                                                                                                                        • didnt work either

                                                                                                                          – khalil
                                                                                                                          Jan 10 '13 at 8:56






                                                                                                                        • 1





                                                                                                                          It's about the tableHeaderView, which is a static view. - [UITableView reloadData] is only intended for the dynamic views (cells) and also the sectionHeaders which you obviously thought were meant ;)

                                                                                                                          – Julian F. Weinert
                                                                                                                          Jul 16 '15 at 11:29














                                                                                                                        -3












                                                                                                                        -3








                                                                                                                        -3







                                                                                                                        Did you try
                                                                                                                        [self.tableView reloadData] after changing the height?






                                                                                                                        share|improve this answer













                                                                                                                        Did you try
                                                                                                                        [self.tableView reloadData] after changing the height?







                                                                                                                        share|improve this answer












                                                                                                                        share|improve this answer



                                                                                                                        share|improve this answer










                                                                                                                        answered Dec 5 '08 at 1:11









                                                                                                                        codelogiccodelogic

                                                                                                                        55k95354




                                                                                                                        55k95354













                                                                                                                        • I've tried this but the header didn't resized.

                                                                                                                          – wal
                                                                                                                          Aug 19 '10 at 20:22











                                                                                                                        • didnt work either

                                                                                                                          – khalil
                                                                                                                          Jan 10 '13 at 8:56






                                                                                                                        • 1





                                                                                                                          It's about the tableHeaderView, which is a static view. - [UITableView reloadData] is only intended for the dynamic views (cells) and also the sectionHeaders which you obviously thought were meant ;)

                                                                                                                          – Julian F. Weinert
                                                                                                                          Jul 16 '15 at 11:29



















                                                                                                                        • I've tried this but the header didn't resized.

                                                                                                                          – wal
                                                                                                                          Aug 19 '10 at 20:22











                                                                                                                        • didnt work either

                                                                                                                          – khalil
                                                                                                                          Jan 10 '13 at 8:56






                                                                                                                        • 1





                                                                                                                          It's about the tableHeaderView, which is a static view. - [UITableView reloadData] is only intended for the dynamic views (cells) and also the sectionHeaders which you obviously thought were meant ;)

                                                                                                                          – Julian F. Weinert
                                                                                                                          Jul 16 '15 at 11:29

















                                                                                                                        I've tried this but the header didn't resized.

                                                                                                                        – wal
                                                                                                                        Aug 19 '10 at 20:22





                                                                                                                        I've tried this but the header didn't resized.

                                                                                                                        – wal
                                                                                                                        Aug 19 '10 at 20:22













                                                                                                                        didnt work either

                                                                                                                        – khalil
                                                                                                                        Jan 10 '13 at 8:56





                                                                                                                        didnt work either

                                                                                                                        – khalil
                                                                                                                        Jan 10 '13 at 8:56




                                                                                                                        1




                                                                                                                        1





                                                                                                                        It's about the tableHeaderView, which is a static view. - [UITableView reloadData] is only intended for the dynamic views (cells) and also the sectionHeaders which you obviously thought were meant ;)

                                                                                                                        – Julian F. Weinert
                                                                                                                        Jul 16 '15 at 11:29





                                                                                                                        It's about the tableHeaderView, which is a static view. - [UITableView reloadData] is only intended for the dynamic views (cells) and also the sectionHeaders which you obviously thought were meant ;)

                                                                                                                        – Julian F. Weinert
                                                                                                                        Jul 16 '15 at 11:29


















                                                                                                                        draft saved

                                                                                                                        draft discarded




















































                                                                                                                        Thanks for contributing an answer to Stack Overflow!


                                                                                                                        • Please be sure to answer the question. Provide details and share your research!

                                                                                                                        But avoid



                                                                                                                        • Asking for help, clarification, or responding to other answers.

                                                                                                                        • Making statements based on opinion; back them up with references or personal experience.


                                                                                                                        To learn more, see our tips on writing great answers.




                                                                                                                        draft saved


                                                                                                                        draft discarded














                                                                                                                        StackExchange.ready(
                                                                                                                        function () {
                                                                                                                        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f341256%2fhow-to-resize-a-tableheaderview-of-a-uitableview%23new-answer', 'question_page');
                                                                                                                        }
                                                                                                                        );

                                                                                                                        Post as a guest















                                                                                                                        Required, but never shown





















































                                                                                                                        Required, but never shown














                                                                                                                        Required, but never shown












                                                                                                                        Required, but never shown







                                                                                                                        Required, but never shown

































                                                                                                                        Required, but never shown














                                                                                                                        Required, but never shown












                                                                                                                        Required, but never shown







                                                                                                                        Required, but never shown







                                                                                                                        Popular posts from this blog

                                                                                                                        Guess what letter conforming each word

                                                                                                                        Port of Spain

                                                                                                                        Run scheduled task as local user group (not BUILTIN)