5

正如我在标题中提到的,我想添加Navigation Controller到我已经有一个Tab Controller. 所以试着在这个页面上做一些类似的事情。无论如何,有些不对劲。UINavigationController正在寻找一个空白页,即使有一个视图和一些库。

让我从stracht开始:

在我的AppDelegate中,我正在设置标签栏控制器,如下所示:

@interface MYAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) UITabBarController *tabBarController;

@end

这是 .m 文件:

@implementation MYAppDelegate

@synthesize window = _window;
@synthesize tabBarController = _tabBarController;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    application.applicationSupportsShakeToEdit = YES;
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    UINavigationController *viewController1 = [[[MYMainViewController alloc] init] initWithNibName: @"MYMainViewController" bundle:nil];
    UIViewController *viewController2 = [[[MYPageViewController alloc] init] initWithNibName:@"MYPageViewController" bundle:nil];
    UIViewController *viewController3 = [[[MYSearchViewController alloc] init] initWithNibName:@"MYSearchViewController" bundle:nil];
    UIViewController *viewController4 = [[[MYPersonViewController alloc] init] initWithNibName:@"MYPersonViewController" bundle:nil];

    // Initialize tabBarController and add ViewControllers
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects: viewController1, viewController2, 
        viewController3, viewController4, nil];

    self.window.rootViewController = self.tabBarController;
    [self.window makeKeyAndVisible];

    return YES;
}

然后,这里是MYMainViewController实现,它是UINavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"%@", [self navigationController]); // Logging null
}

我的 .xib 文件有一个UINavigationController和,其中有一个视图。尽管如此,当我使用该应用程序时,有空白页面和无标题导航栏。我究竟做错了什么?

如果我可以看到我的视图的内容,我想通过使用后退按钮在两个视图控制器之间导航。

任何帮助或方法对我来说都会很棒。

4

1 回答 1

4

尝试从 xib 中删除导航控制器,使其只有视图控制器,然后以编程方式初始化导航控制器:

UIViewController *tmpViewController1 = [[[YourViewController alloc] init] initWithNibName:@"YourViewController" bundle:nil];
 UINavigationController *viewController1 =  [[UINavigationController alloc] initWithRootViewController:tmpViewController1];
于 2012-12-25T12:12:20.897 回答