how to add uinavigation controller in a view based application

前端 未结 4 1152
甜味超标
甜味超标 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:16

    If you want to have a navigation controller as the root view for your main window. Then you can do so by using the following code.

    @interface yourAppDelegate_iPad : NSObject  {
        UINavigationController *navigationController;
    }
    
    @property (nonatomic, retain) UINavigationController *navigationController;
    
    @end
    
    @implementation yourAppDelegate
    @synthesize navigationController;
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
        navigationController = [[UINavigationController alloc] initWithRootViewController:yourRootViewController];
        [self.window addSubview:navigationController.view];
        [self.window makeKeyAndVisible];
        return YES;
    }
    

    You can do this by using the xib as follows

    1. Open the MainWindow.xib
    2. Drag and drop a UINavigationController to it.
    3. Create and connect the outlets.
    4. Open attributes for the navigation controller and set the root view.

提交回复
热议问题