tags:

views:

1233

answers:

4

My main controller is a subclass of UITableViewController with a UIToolBar at the bottom and when a row is selected, I'd like to display another view without the toolbar. How can I hide the UIToolBar in the child view? Right now, it's present throughout all child views unless they're created as modal.

Toolbar is created in RootController:

self.toolbar = [[UIToolbar alloc] init];
// add tool bar items here
[self.navigationController.view addSubview:toolbar];

RootController displays its child views as such:

UIViewController *controller = [[UIViewController alloc] init...]
[self.navigationController pushViewController:controller animated:YES];

RootController is instantiated as such in the app delegate's applicationDidFinishLaunching:

RootController *rootcontroller = [[RootController alloc] initWithStyle:UITableViewStyleGrouped];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:rootcontroller];

[rootcontroller release];

[window addSubview:[self.navigationController view]];

If I add the toolbar to [self.view] within RootController instead of navigationController's view, the toolbar disappears alltogether..

+2  A: 

You can try hiding the toolbar before you display our child view with 'toolbar.hidden = YES' and then in your viewWillAppear method, show it again with 'toolbar.hidden = NO'.

Alexi Groove
A: 

Another alternative would be using "removeFromSuperview"

[toolbar removeFromSuperview];

Then use viewDidAppear method in the view where u wanna re-show the toolbar. It works better than viewWillAppear since the toolbar is added after the view is showed. (For viewWillAppear, toolbar is added during the transition so it is kinda awkward.)

A: 

I got it working with this

[toolbar removeFromSuperview];

Check this

  • (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated];

//Initialize the toolbar toolbar = [[UIToolbar alloc] init]; toolbar.barStyle = UIBarStyleDefault;

//Set the toolbar to fit the width of the app. [toolbar sizeToFit];

//Caclulate the height of the toolbar CGFloat toolbarHeight = [toolbar frame].size.height;

//Get the bounds of the parent view CGRect rootViewBounds = self.parentViewController.view.bounds;

//Get the height of the parent view. CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds);

//Get the width of the parent view, CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds);

//Create a rectangle for the toolbar CGRect rectArea = CGRectMake(0, rootViewHeight - toolbarHeight, rootViewWidth, toolbarHeight);

//Reposition and resize the receiver [toolbar setFrame:rectArea];

//Create a button UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(info_clicked:)];

[toolbar setItems:[NSArray arrayWithObjects:infoButton,nil]];

//Add the toolbar as a subview to the navigation controller. [self.navigationController.view addSubview:toolbar];

[[self tableView] reloadData];

}

  • (void) info_clicked:(id)sender {

[self.navigationController popViewControllerAnimated:YES]; [toolbar removeFromSuperview];

}

Hope this helps. It worked for mw

Thanks Viki

A: 

I am not sure if this is the soultion. It worked for me....