问题描述
我在使用xibs而不是storyboard启动iOS应用程序时遇到了一些麻烦。问题是我得到一个黑屏并且没有调用第一个视图控制器(将断点添加到 viewDidLoad
方法)。
Im having some troubles to start an iOS app using xibs instead of storyboard. The problem is that im getting a black screen and the first view controller is not being called (added break point to viewDidLoad
method).
在app delegate标题中,我声明了这一点:
In the app delegate header i have declared this:
@property (strong, nonatomic) UIWindow window;
@property (strong, nonatomic) ViewController *viewController;
在 didFinishLaunchingWithOptions
方法中我有这个实现:
And in the didFinishLaunchingWithOptions
method i have this implementation:
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
navController.navigationBarHidden = YES;
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
查看一些论坛我发现我应该分配窗口所以我添加了这个作为第一行函数
Looking over some forums i found that i should be allocing the window so i added this as the first line of the function
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
问题是,当我这样做时,应用程序在从 didFinishLaunchingWithOptions 方法(SIGABRT没有任何痕迹)。
The problem is that, when i do this, the app crashes after returning from didFinishLaunchingWithOptions
method (SIGABRT without any trace).
我还尝试制作 navController
一个属性,并且还实例化一个默认的 UIViewController
类,启动相同的xib
I also tried to make the navController
a property and also instantiating a default UIViewController
class initing the same xib
我做错了什么?
谢谢和问候
推荐答案
好的,最后我明白了。
OK, at last i got it.
我只需要再次添加
self.window = [ [UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
在此之后,只需删除.h,.m和。 xib并再次创建它们。
After this, just delete the .h, .m and .xib and create them again.
由于任何原因它现在正常工作。
For any reason its working fine now.
这篇关于启动没有故事板的ios项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!