Resolved Multiple views...separate toolbar in each?

Discussion in 'iOS Programming' started by JezzerP, Apr 5, 2011.

  1. JezzerP, Apr 5, 2011
    Last edited: Apr 6, 2011

    macrumors newbie

    Joined:
    Apr 1, 2011
    Location:
    York, UK
    #1
    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 :)
     
  2. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #2
    Your desired set-up is possible (and recommended). Perhaps include some code and/or IB screenshots so we can help troubleshoot.
     
  3. thread starter macrumors newbie

    Joined:
    Apr 1, 2011
    Location:
    York, UK
    #3
    Thanks for the quick response...will try and upload some screen shots and code some time soon.
     
  4. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #4
    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.
     
  5. thread starter macrumors newbie

    Joined:
    Apr 1, 2011
    Location:
    York, UK
    #5
    I just dragged it onto the xib and it looks like it's been placed as a subview:

    [​IMG]

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

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

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #6
    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.
     
  7. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    What are you seeing instead when you run the app?
     
  8. thread starter macrumors newbie

    Joined:
    Apr 1, 2011
    Location:
    York, UK
    #8
    The NotesViewController was created in the MainWindow.xib:

    [​IMG]

    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:

    [​IMG]
     
  9. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    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.
     
  10. thread starter macrumors newbie

    Joined:
    Apr 1, 2011
    Location:
    York, UK
    #10
    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:

    [​IMG]

    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!! ;)
     
  11. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #11
    Add this to your viewDidLoad

    Code:
    NSLog(@"%@", notesToolBar);
    NSLog(@"%@", NSStringFromCGRect(notesToolBar.frame));
    and let us know what it prints.
     
  12. Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #12
    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.
     
  13. thread starter macrumors newbie

    Joined:
    Apr 1, 2011
    Location:
    York, UK
    #13
    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;)
     

Share This Page