views:

616

answers:

5

If I attempt to animate the frame height of a tableView (ex: height -= 200), the cells that appear in the last 200px disappear suddenly before the smooth animation of the frame completes.

To make sure that it's nothing else I'm doing, I created a new View-Based application. In the main viewController I create my own tableview with enough pseudo rows to fill the entire screen. And on selection of a row I do a simple height animation.

most relevant code:

- (void)viewDidLoad {
    [super viewDidLoad];
    self.myTable = [[[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)] autorelease];
    myTable.delegate = self;
    myTable.dataSource = self;
    [self.view addSubview:myTable];
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    CGRect frame = self.myTable.frame;
    frame.size.height = 200;
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    [UIView setAnimationDelay:.5f];
    [UIView setAnimationDuration:0.5f];
    self.myTable.frame = frame;
    [UIView commitAnimations];
}

Does anyone know why this is happening, or what a fix/workaround may be?

Any suggests are really appreciated. TIA!

A: 

I found your question while seeking the proper method to resize a tableView. I think your problem is in your animation you've specified "UIView" instead of UITableView. I was unable to duplicate your problem using either UIView or UITableView, but I'm using SDK 3.1 and it might be a bug that has been fixed since your post. I'm not sure, but I hope this helps!

Michael
No, it's correct to use "UIView" methods for the animation calls.
racha
I tried the same code with 3.1 as well, and still an issue for me ;/ My current workaround is to wait for the animation to complete before resizing the tableview
dizy
A: 

I have exactly the same problem. I imagine that tableviews have a special behavior on "setFrame:", it seems that the tableview remove the cells that won't be visible with the new frame.

In case of an animation, the cells won't be visible only at the end of the animation, but it seems that tableviews don't care.

If someone have a better theory, I'd be glad to hear it !

Unfalkster
+1  A: 

Same problem here as well. This is what I'm doing and the origin animates smoothly, but the size changes immediately... annoying.

    [UIView beginAnimations:@"HideTabbar" context:nil];
    [UIView setAnimationDuration:.3];
        self.tableView.frame = CGRectMake(0.0, 44.0, 320, 366);
    [UIView commitAnimations];

UPDATE: Try adding this before the animation:

self.tableView.autoresizingMask = UIViewAutoresizingNone;
Jonah
A: 

Same problem here. Anyone find a solution?

Phillip
Please up-vote the question rather than adding a "me too" non-answer.
Stephen Darlington
A: 

Similar issue here. When I animate a positive change in height to one of (or all of) our store tables, the tables grow smoothly as expected, but the table cells (and their subsequent subviews) all slide into place from behind the other cells in an ugly fashion. (The subviews actually animate to their position WITHIN the cell from the top left, which is even uglier)

I'd prefer if I could just somehow tell it "Do not animate the display of new cells", but I'm not sure how at the moment.

I tried messing with "willDisplayCell" for some time, to no avail.

Just to be a little more specific:

I have tables displayed in a container view. The tables all have resizing masks for their height (Confirmed that they are not the issue). The animation resizes the container view.

Resizing the tables directly still gives the same result.