简体   繁体   English

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

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

I have a Navigation Controller in my main view and also subview. 我的主视图和子视图中都有一个导航控制器。 And I use the following code to add the navigation view when needed. 并且我使用以下代码在需要时添加导航视图。

In appdelegate.h page 在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

In appdelegate.m 在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;
}

This code work when press the button 按下按钮时此代码有效

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

However, the navigation bar is not positioned correctly. 但是,导航栏的位置不正确。 I have posted a pic below. 我在下面发布了一张图片。 Anyone knows what is the potential problem? 谁知道潜在的问题是什么? And how to solve this gap of navigationbar? 以及如何解决导航栏的这一空白? Help me anyone. 帮帮我。 Thanks in advance. 提前致谢。 Here i can post the image. 在这里我可以发布图像。 So i have posted a pic in the link Image 所以我在链接图片中贴了一张图片

Remove this line from your code [self.window addSubview:viewController.view]; 从您的代码中删除此行[self.window addSubview:viewController.view];

you first load your View controller than after load your navigationController instead this only navigationController.VIew you have to add on window.. 您首先要加载View控制器,而不是先加载NavigationController,然后才加载仅NavigationController。这时您必须在窗口上添加。

hope it`s solve your problem. 希望它能解决您的问题。

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

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