PDA

View Full Version : [Resolved] Multiple views...separate toolbar in each?




JezzerP
Apr 5, 2011, 10:51 AM
Hi, working on my first iPhone app and having trouble with toolbars. I have four separate views in the app, controlled by a TabBar in the app delegate class. Each view has it's own view controller class and it's own xib file. So far so good...when I run the app, I can change view using the tab bar. If I put other controls in the different views these show up and behave as expected. However, what I would like to do is have a toolbar at the top of some of the views (not all), and have different controls embedded in each. I can put a toolbar object and embedded controls in the xib of a view, but when I run the app, the toolbar is not visible. Is this set-up even possible, or do I have to have a single toolbar in the app delegate class and control the showing/hiding and embedded controls programatically when the view changes?

I hope I've made myself clear!! Thanks :)



dejo
Apr 5, 2011, 10:57 AM
Is this set-up even possible, or do I have to have a single toolbar in the app delegate class and control the showing/hiding and embedded controls programatically when the view changes?
Your desired set-up is possible (and recommended). Perhaps include some code and/or IB screenshots so we can help troubleshoot.

JezzerP
Apr 5, 2011, 11:00 AM
Thanks for the quick response...will try and upload some screen shots and code some time soon.

PhoneyDeveloper
Apr 5, 2011, 11:12 AM
A toolbar is a view like other views. If you add it to a view hierarchy it should show up. Have you added it as a subview of a container view or at the top level in the nib? It should be a subview.

JezzerP
Apr 5, 2011, 01:07 PM
A toolbar is a view like other views. If you add it to a view hierarchy it should show up. Have you added it as a subview of a container view or at the top level in the nib? It should be a subview.

I just dragged it onto the xib and it looks like it's been placed as a subview:

http://www.gabbrosoft.org/images/for%20forums/XCode-01.jpg

Do I have to 'add' it to the view in code, as I do with my TabBar:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[_window addSubview:tabBarController.view];
[_window makeKeyAndVisible];
return YES;
}

PhoneyDeveloper
Apr 5, 2011, 01:39 PM
No code should be required to make that toolbar appear, other than the normal loading of the nib. You would want an IBOutlet if you need to access the toolbar in code for something else though.

How do you load the NotesViewController? Is it just created in MainWindow.xib?

Anyway, the toolbar should appear along with any other views in the nib.

dejo
Apr 5, 2011, 01:42 PM
What are you seeing instead when you run the app?

JezzerP
Apr 5, 2011, 02:23 PM
The NotesViewController was created in the MainWindow.xib:

http://www.gabbrosoft.org/images/for%20forums/XCode-02.jpg

When I run the app I do not see the Toolbar at all...just the TabBar, and in the particular view in question, the TextField:

http://www.gabbrosoft.org/images/for%20forums/Simulator-01.png

PhoneyDeveloper
Apr 5, 2011, 02:32 PM
I suspect that the toolbar is there it's just offscreen or hidden for some reason.

Check that it doesn't have the hidden flag set or have an alpha of 0.0 or something else like that. Check its springs and struts to make sure it isn't moving itself offscreen.

If that doesn't help make it an IBOutlet and check its value in viewDidLoad and also its frame.

JezzerP
Apr 5, 2011, 03:15 PM
Hidden flag not set, alpha set to 1, but not quite sure what you mean by 'springs and struts' :confused:

When I add an outlet and break in viewDidLoad, it's looking like I have a valid object:

http://www.gabbrosoft.org/images/for%20forums/XCode-03.jpg

Anyway, thanks for all your help so far...I'm going to have to pick this up in the morning....having a one year old lad means i need to get to bed early!! ;)

PhoneyDeveloper
Apr 5, 2011, 03:51 PM
Add this to your viewDidLoad

NSLog(@"%@", notesToolBar);
NSLog(@"%@", NSStringFromCGRect(notesToolBar.frame));

and let us know what it prints.

dejo
Apr 5, 2011, 04:10 PM
Also, in your NotesView.xib, make sure you have added a Tab Bar as Bottom Bar for your Simulated Metrics. If you do this after you've already added your Tool Bar, the Tool Bar may get bumped off the top. Move it back (you may notice in the Size Inspector that the toolBar's Y origin is now -49) or delete and re-add it.

JezzerP
Apr 6, 2011, 03:19 AM
Also, in your NotesView.xib, make sure you have added a Tab Bar as Bottom Bar for your Simulated Metrics. If you do this after you've already added your Tool Bar, the Tool Bar may get bumped off the top. Move it back (you may notice in the Size Inspector that the toolBar's Y origin is now -49) or delete and re-add it.

That was it!! I'd forgotten to add a simulated bottom tabbar....why is it always the simple things that trip you up?

Anyway, thanks for all the help. I must admit that I am very grateful for the rapid responses...the same question on the Apple Dev101 forum has gone unanswered for two days...guess I know where to come in the future;)