views:

375

answers:

1

I have the following view hierarchy

UITabBarController - UINavigationController - UITableViewController

When the table view appears (animated) I create a toolbar and add it as subview of the TabBar at the bottom of the page and let it animate in with the table view. Same procedure in other direction, when the table view disappears.

It does not work as expected.

  • The animation duration is OK, but somehow not exact the same as the animation of the table view when it becomes visible
  • When I display the table view for the second time, the toolbar does not disappear at all and remains at the bottom of the parent view.

What's wrong with it?

- (void)animationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
   UIView *toolBar = [[[self tabBarController] view] viewWithTag:1000];
   [toolBar removeFromSuperview];
}

- (void)viewWillAppear:(BOOL)animated 
{
   UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 44, 0);
   [[self tableView] setContentInset:insets];
   [[self tableView] setScrollIndicatorInsets:insets];
   // Toolbar initially placed outside of the visible frame (x=320)
   UIView *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(320, 480-44, 320, 44)];
   [toolBar setTag:1000];
   [[[self tabBarController] view] addSubview:toolBar];

   [UIView beginAnimations:nil context:nil];
   [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
   [UIView setAnimationDuration:0.35];
   [toolBar setFrame:CGRectMake(0, 480-44, 320, 44)];
   [UIView commitAnimations];
   [toolBar release];

   [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
   UIView *toolBar = [[[self tabBarController] view] viewWithTag:1000];

   [UIView beginAnimations:nil context:nil];
   [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
   [UIView setAnimationDuration:0.35];
   [UIView setAnimationDidStopSelector:@selector(animationDone:finished:context:)];
   [toolBar setFrame:CGRectMake(320, 480-44, 320, 44)];
   [UIView commitAnimations];

   [super viewWillDisappear:animated];
}
A: 

Have you tried just using the table view controller's toolbarItems property? UINavigationController will manage a toolbar for you, updating it with the toolbar items of its current topmost view controller; use the -setToolbarHidden:animated: method in your -viewWillAppear: and -viewWillDisappear: to control the visibility of that toolbar.

Noah Witherspoon
You mean the toolbar of the navigation controller, right? I need another toolbar at the bottom of the table but it should not be moved with the table contents when scrolling up and down.In the code above I experiment a little bit with the animation but the toolbar will only become visible when the table turns in editing mode. Hmmm... once again a UIViewController as "container" for the UITableViewController could be a solution.
MacTouch
OK, solved it using a simple UIViewController instead of UITableViewController. It works similar to the following example: http://iphonedevelopment.blogspot.com/2008/10/table-view-multi-row-edit-mode.html
MacTouch