以编程方式创建UINavigationController(iOS9,ObjC)

时间:2015-10-12 12:46:38

标签: ios objective-c uinavigationcontroller ios9 xcode7

我想以编程方式创建一个UINavigationController 我已经在互联网上关注了一些教程但是我仍然收到错误消息,即使我已经逐步详细地按照教程。

我使用当前代码得到的错误如下:

  

***由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:'无法加载NIB   捆绑:' NSBundle      (加载)'名称' BrowserController''

我的代码看起来像这样:

.h文件:

#import <UIKit/UIKit.h>
@class BrowserController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) BrowserController *rootViewController;
@property (strong, nonatomic) UINavigationController *navigationController;


@end

.m文件:

#import "AppDelegate.h"
#import "BrowserController.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    self.window.backgroundColor = [UIColor whiteColor];


    self.rootViewController = [[BrowserController alloc] initWithNibName:@"BrowserController" bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.rootViewController];
    [self.window addSubview: self.navigationController.view];
    self.window.rootViewController = self.rootViewController;

    [self.window makeKeyAndVisible];
    return YES;
}

0 个答案:

没有答案