How Do Implement Nav Controller To DidFinishLaunching?

Discussion in 'iOS Programming' started by loon3y, Nov 8, 2011.

  1. loon3y macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #1
    where do i add the nav controller in the did finish launching in the app delegate?

    Code:
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
       
        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        // Override point for customization after application launch.
        UIViewController *viewController1 = [[[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil] autorelease];
        UIViewController *viewController2 = [[[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil] autorelease];
        UIViewController *viewController3 = [[[ThirdViewController alloc] initWithNibName:@"ThirdViewController" bundle:nil] autorelease];
        UIViewController *viewController4 = [[[FourthViewController alloc] initWithNibName:@"FourthViewController" bundle:nil] autorelease];
        self.tabBarController = [[[UITabBarController alloc] init] autorelease];
        self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, viewController3, viewController4, nil];
        self.window.rootViewController = self.tabBarController;
        [self.window makeKeyAndVisible];
        return YES;
    }
    
    
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
    How you want the navigation controller to fit in with your current tab bar controller?
     
  3. loon3y thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #3


    i juz need navigation controller with my fourth view controller, because it wil be a table view.


    but i may add nav controller to my other view controllers later on when i add more features
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    Are you doing it all in code or in Xibs?
    Because you need to add a UINavigationController, set his rootController to the viewController, and add the NavigationController as viewControllers to your tabcontroller.
    Or just do it in a XIB.
     
  5. loon3y thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #5
    which ever is better for my situation, is there a difference?


    if not i rather do it the simple way and do it in the xib
     
  6. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    Okay, the easy way is this ->
    Open your MainWindow.xib, delete everything exept your window. add a UITabbarController, it will have 2 tabs standard, if you tick it open (your UITabbarController), there should be 2 ViewControllers, change that to 2 NavigationControllers, or more, if you add another one, it will add it automagically :)
    Then on the Navigation, tick that open, it will have a view controller within, click on that, and on the properties, assign the corresponding ViewController CLASS and NIB (2 seperate properties windows).
    In Appdelegate, make an IBOutlet for your window (which you will have), and an IBOutlet to your UITabbarController. don't forget to hook it up in interface builder..
    Then, just do
    Code:
     [self.window addSubview:tabOutlet.view]; 
    And that should suffice :)
    Good luck, and for more specific questions, go ahead.
     
  7. loon3y thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #7

    i don't have a main xib, i created this in Xcode 4.2,


    it seems like i should make a new project? and copy all my old stuff to the new one?

    because i have ALOT of stuff on my 1st and 3rd view controllers.

    its linked up with linea pro barcode scanner and credit card reader.
     
  8. loon3y thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #8
    I'm learning storyboard mode, it seems a lot easier than manually implementing navigation and tab bar,


    is there something wrong with storyboard mode? how come nobody suggested it?
     
  9. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #9
    Easy, since it's a fairly new solution, and I just haven't got the time to check it out.
    Second, I started a new project, tried to build it our testing device, which runs 4.3.5, and it says, storyboard doesn't work prior iOS5, which is weird. But I support back to 4.0, so i stick to the old solution, create my appdelegate/mainwindow all by hand, at least then I know what i'm doing.
     
  10. loon3y thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #10
    it was just too hard for me, I'm a noob to programming, generally, not just iOS.

    i literally had to look up everything for my app, a co-worker helped me out, but he can help me only so much, and he's not an iOS/ or C programmer at all.

    until i get more expierneced i juz have to do the mickey mouse way of doing it, cuz i also have a deadline for this project and customers are waiting.
     
  11. jnoxx, Nov 10, 2011
    Last edited by a moderator: Nov 10, 2011

    jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #11
    Looks like you are in the position I was in 2 years ago, when I started, i haven't had coded a line in my life, and got thrown into a new OS (MAC OSX) and iOS, and I had to build an app for a big magazine.. i was like, de ****. And I was the only one who programmed iOS.
    But like I said, you will have to invest private time into this, that's what I did, and when I finally came around and to love it all, i don't do anything else.
    You can opt for rolling back on your Xcode, to 4.0/4.1, or learn how to manually implement your MainWindow. I can teach you, but I don't have alot of time neither.
     
  12. loon3y thread starter macrumors 65816

    loon3y

    Joined:
    Oct 21, 2011
    #12
    lol damn, i hope my situation ends up like yours,


    i know how to create a main window, i looked up online when Xcode 4.2 first came out and it had no main window xib.

    i just don't know how to implement it to my app once i make it, where i put the coding to connect it all whether its in the .h or .m.


    well i hope u do get some free time lol.

    are you still working at the magazine company?
     
  13. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #13
    No, that was a client of us. That's why I was in your position, had a deadline for a client. I work as a full time Front-End Developer now for iOS Business apps, and I'm starting up my own company on the side for Mobile development in general.

    Now to your problem, if you have a Mainwindow.xib (if you created an INTERFACE appdelegate and called it Mainwindow). It should have the yellow App delegate object in the view hierachy, you have to assign your APPDELEGATE CLASS to this object. Then you will have it's properties when you right click on it, then you should do what I all did in the above posts. And connect it properly, then on your Xcode project -> target -> Summary, you can still assign it's - Main Window -.
    If you do that, it should all work out.
     
  14. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #14
    Or you can mix the use of code and XIBs.

    I think all this talk of MainWindow.xib is a distraction and unnecessary. The OP just needs to take the code from their thread starter and just wrap whatever viewControllers they want to have in a nav stack with UiNavigationControllers. This can be done pretty simply in code.
     
  15. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #15
    Well, yeah, there are options, that's why i opt for reading books on iPhone Development ;)
     
  16. micharadi macrumors newbie

    Joined:
    Dec 2, 2006
    #16

Share This Page