AppDelegate.m
_viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:_viewController];
nav.navigationBar.barStyle = UIBarStyleBlackOpaque;
[_window addSubview:nav.view];
ViewContoller.m
UINavigationController *nav = self.navController;
[nav pushViewController:controller animated:YES];
我不知道为什么UINavigationController
总是为零。
请帮助!!
答案 0 :(得分:1)
不要将navigationController
的视图添加为window
的{{1}},而是尝试将subview
添加为窗口navigationController
rootViewController
答案 1 :(得分:0)
新解决方案
试试这个
AppDelegate.m 中的
@implementation AppDelegate
{}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *_navController = [[UINavigationController alloc] init];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.rootViewController = _navController;
ViewController* _viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[_navController pushViewController:_viewController animated:YES];
return YES;
}
在 ViewContoller.m 中现在可以使用:
UINavigationController *nav = self.navigationController;
[nav pushViewController:controller animated:YES];
旧解决方案
试试这段代码
AppDelegate.h 中的一定要至少
@interface AppDelegate : NSObject <UIApplicationDelegate>
{}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@end
在 AppDelegate.m 至少这个
@implementation AppDelegate
{}
@synthesize window=_window;
@synthesize navController=_navController;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UINavigationController *_navController = self.window.rootViewController;
UIViewController* _viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[_navController pushViewController:_viewController animated:YES];
return YES;
}
@end
故事板中的一定要创建一个绑定到ViewController的NavigationController,定义为初始视图控制器并绑定为绑定视图控制器的根视图控制器
在应用常规设置标签中,请务必在部署信息部分设置故事板(在本节中也可以设置状态栏样式)
在 ViewContoller.m 中现在可以使用:
UINavigationController *nav = self.navigationController;
[nav pushViewController:controller animated:YES];
编辑navigationBar样式,你可以这样做
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.barStyle = UIBarStyleBlackOpaque;
}
答案 2 :(得分:0)
homeViewController = (mainStoryboard.instantiateViewControllerWithIdentifier("register") as? RegisterViewController)!
let navigationController :UINavigationController = UINavigationController()
navigationController.pushViewController(homeViewController, animated: true)
navigationController.navigationBarHidden = false
window?.rootViewController = nil
window?.rootViewController = navigationController
window?.makeKeyWindow()
答案 3 :(得分:0)
{{1}}