XibでUINavigationControllerを使う方法です。
基本的に、AppDelegateにいい感じで記述すればOKです
AppDelegate.h
#import <UIKit/UIKit.h>
@class ViewController;
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) ViewController *ViewController;
@end
クラスにController名を設定し、クラスのインスタンスを作成します。
AppDelegate.m
import
#import "ViewController.h"
表示したいxibに紐づけられたcontrollerをimportする
didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#pragma mark -xib化
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.ViewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController: self.ViewController];
navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.6392 green:0.709 blue:0.3529 alpha:1.0];
navigationController.navigationBar.tintColor = [UIColor whiteColor];
navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName: [UIColor whiteColor]};
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;
このようにAppDelegate.mのdidFinishLaunchingWithOptionsに記述します。
したら、navigationbarが全てのviewに現れます。