簡體   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