how to add uinavigation controller in a view based application

前端 未结 4 1113
甜味超标
甜味超标 2021-01-23 01:15

I wanted to add a navigation controller to a view based application . how can we do this both programmatically and using xib file..

4条回答
  •  伪装坚强ぢ
    2021-01-23 02:14

    If you need to incorporate a navigation controller in your uiviewcontroller you need to initialize it as it follows

    UIViewController *yourViewController = ...
    
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:yourViewController];
    
    [self presentModalViewController:navController animated:YES];
    
    //you need to release the controller
    [navController release];
    

    If you are in the UIApplicationDelegate method

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    

    You can't do a presentModalViewController:navController animated... then you need to add the navController.view to the window

        UIViewController *yourViewController = ...
    
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:yourViewController];
        [self.window addSubview:navController.view];
        //don't do a release of navController because is not retained by addSubview
    

提交回复
热议问题