views:

2274

answers:

3

I know how to add a UIToolbar, which I'm doing in rootviewcontroller.m:

[self.navigationController.view addSubview:toolbar];

However, when I navigate to other views, the toolbar stays up, which is ok, but how do I access it to hide/show it?

Inside rootviewcontroller I would use this:

toolbar.hidden = NO;

But I can't seem to find a way to do this outside of rootviewcontroller.m

Can you please show me an example of hiding it from another class?

+2  A: 

There are two options;

1) Add a property to your controller so external classes can access to the toolbar object.

2) Add a function to your root view controller that can be used to toddle the toolbar.

I would recommend #2 since it restricts what external classes can do.

E.g.

-(void) showToolbar:(BOOL)hidden
{
  toolbar.hidden = hidden;
}
Andrew Grant
+1  A: 

The problem is that you shouldn't be adding it to self.navigationController.view; you should be adding it to self.view. Correcting that should fix it for you.

Brent Royal-Gordon
A: 

Andrew Grant's answer is what you're looking for. However, you should rename the method to

-(void) isToolbarHidden:(BOOL)hidden {
    toolbar.hidden = hidden;

}

It makes more sense that way when looking at the code.

JustinXXVII