cmos
cmos

Reputation: 629

UIToolbar and other views

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?

Upvotes: 2

Views: 5331

Answers (4)

Andrew Grant
Andrew Grant

Reputation: 58804

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) hideToolbar:(BOOL)hidden
{
  toolbar.hidden = hidden;
}

Upvotes: 3

nosuic
nosuic

Reputation: 1360

You could try adding the following line during the initialisation of the View Controllers for which you don't want the bar to appear.

[self.navigationController setToolbarHidden:YES animated:NO];

F.

Upvotes: 0

Daddy
Daddy

Reputation: 9035

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.

Upvotes: -1

Becca Royal-Gordon
Becca Royal-Gordon

Reputation: 17871

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.

Upvotes: 2

Related Questions