繁体   English   中英

NavigationBar定位不正确。 如何解决这个问题呢?

[英]NavigationBar not positioned correctly. How to solve this problem?

我的主视图和子视图中都有一个导航控制器。 并且我使用以下代码在需要时添加导航视图。

在appdelegate.h页面中

    @interface AapkeappsAppDelegate : NSObject <UIApplicationDelegate, UINavigationControllerDelegate> {
UIWindow *window;
AapkeappsViewController *viewController;
UINavigationController *navigationController; 
}
 @property (nonatomic, retain) IBOutlet UIWindow *window;
 @property (nonatomic, retain) IBOutlet AapkeappsViewController *viewController;
 @property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
 @end

在appdelegate.m中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
  (NSDictionary *)launchOptions 
{    
    UINavigationController *nvcontrol =[[UINavigationController alloc]   
               initWithRootViewController:viewController];
[self.window addSubview:viewController.view];
[self.window addSubview:nvcontrol.view];
[window makeKeyAndVisible]; 
return YES;
}

按下按钮时此代码有效

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

但是,导航栏的位置不正确。 我在下面发布了一张图片。 谁知道潜在的问题是什么? 以及如何解决导航栏的这一空白? 帮帮我。 提前致谢。 在这里我可以发布图像。 所以我在链接图片中贴了一张图片

从您的代码中删除此行[self.window addSubview:viewController.view];

您首先要加载View控制器,而不是先加载NavigationController,然后才加载仅NavigationController。这时您必须在窗口上添加。

希望它能解决您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM