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
@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
- (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];
you first load your View controller than after load your navigationController instead this only navigationController.VIew you have to add on window..
hope it`s solve your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.