1

I have a Storyboard with a UITableView. The tableView gets a tableViewHeader like:

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

The button appears only if a condition is met. Also, if the button is clicked the header must be:

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

I tried lots of things, like:

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

This works great if I click the button. But once I scroll the table view up, it bounces at 0 and then offset is lost, my table view looks like:

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

I also tried all kinds of views manipulation and tried reset the tableViewHeader, like:

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

Getting the result:

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

I saw something about changing my UITableViewController to a UIViewController and my problems will be resolved by manipulating the view controller frame, but I have like 10 table view and I don't really have time to make all the changes I need.

Please, can someone help me?

3 Answers 3

5

I got similar issue resolved by re-assigning the same object to the table view header:

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

Note that table header view should already be resized prior to this assignment.

Sign up to request clarification or add additional context in comments.

Comments

0

Don't know if it is just a copy/paste problem, but I think that when you change the header frame you are missing a step; try with this:

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

If you omit the last assignment, you have just created a local CGRect and modified its value, not actually changed the header's frame.

2 Comments

self.tableView.tableHeaderView.frame = frame causes a constraint crash. I tried to alloc a new frame to solve that.
Unable to simultaneously satisfy constraints. Will attempt to recover by breaking constraint UIView:0x8d77fd0.bottom == UIView:0x8d767e0.bottom. Break on objc_exception_throw.
0

I decided to use a UIViewController with a UITableView inside. My piece of advise here is: forget about the UITableViewController. It is a mess. The solution is:

Button:

- (IBAction)synchronizeTouchUpInside:(id)sender {

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

}

viewWillAppear:

- (void)viewWillAppear:(BOOL)animated {

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

}

Now I just need to rebuild a lot of table view controllers. C'est la vie.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.