2 subview for windows?

Discussion in 'iOS Programming' started by StefanDevil, Sep 21, 2010.

  1. StefanDevil macrumors member

    Joined:
    Jul 31, 2010
    #1
    hi,

    i have this at my appdelegate:

    for 1st app:
    Code:
           
           - (void)applicationDidFinishLaunching:(UIApplication *)application {    
        
    	   [window addSubview:rootController.view];
    	   [window makeKeyAndVisible];
          }
    
    
    this will display a navigation and tabar display for my app.

    ok no problem here.

    next i have this from another app:
    Code:
           - (void) applicationDidFinishLaunching:(UIApplication *)application {    
    	      _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    	     MainViewController *_mainViewController = [[MainViewController alloc] init];
    	      UINavigationController *_navigationController = [[UINavigationController alloc] initWithRootViewController:_mainViewController];
    
    	     [_window addSubview:_navigationController.view];
    	       [_window makeKeyAndVisible];
               }
    which also works fine.

    now, how can i include all this function into my 1st app? i would like to use it for one of my tab options.

    i've tried:
    Code:
         - (void)applicationDidFinishLaunching:(UIApplication *)application {    
    	
    		Tab4 *_mainViewController = [[Tab4 alloc] init];
    		UINavigationController *_navigationController = [[UINavigationController alloc] initWithRootViewController:_mainViewController];
    		
    		[window addSubview:_navigationController.view];
    	[window addSubview:rootController.view];
    	[window makeKeyAndVisible];
    }
    
    sort of combining the two. there is no compiling error but the program is not working.
    i got it wrong somewhere and stuck. is it possible to have 2 subivew?
    any help is greatly appreciated.
    thks.
     
  2. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #2
    Think about the object hierarchy, it needs to look like this:

    Code:
        UIWindow
            UITabBarController
                UINavigationController
                    MyMainViewController
                SomeOtherControllerShownInTheTabBar
                ...
    
    Or, in other words, the tab bar is the container object and -- within each tab -- you can have whatever UIViewControllers you want (including UINavigationController, UITableViewController, etc.) :)
     
  3. StefanDevil thread starter macrumors member

    Joined:
    Jul 31, 2010
    #3
    hi,

    i've embedded the a nav controller in my tab bar.
    but doing this does it "replace" the code completely?

    Code:
    	      _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
    	     MainViewController *_mainViewController = [[MainViewController alloc] init];
    	      UINavigationController *_navigationController = [[UINavigationController alloc] initWithRootViewController:_mainViewController];
    
    	     [_window addSubview:_navigationController.view];
    	       [_window makeKeyAndVisible];
    
    tab view gets load up fine but it is unable to receive a notification.
    thks
     
  4. ianray macrumors 6502

    Joined:
    Jun 22, 2010
    Location:
    @
    #4
    I'm not sure what you mean. Perhaps you could paste the whole of the applicationDidFinishLaunching method?

    What do you mean by "notification"?
     
  5. StefanDevil thread starter macrumors member

    Joined:
    Jul 31, 2010

Share This Page