[英]How do I use the UINavigationController without a xib?
I have an irrational aversion to the Interface Builder. 我对接口构建器有非理性的厌恶。
Here's what I have so far, all I get is the black screen. 到目前为止,这就是我得到的,只是黑屏。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
// Add the navigation controller's view to the window and display.
PrayViewController* prayViewController = [[PrayViewController alloc] initWithTabBar];
[_window addSubview: [[UINavigationController alloc] initWithRootViewController:prayViewController]];
[prayViewController release];
[self.window makeKeyAndVisible];
return YES;
}
You should add a view to the window, like this: 您应该向窗口添加视图,如下所示:
UIViewController *rootController = [[MyRootViewController alloc] init];
navigationController = [[UINavigationController alloc]
initWithRootViewController:rootController];
[rootController release];
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// *** IMPORTANT DIFFERENCE:
[window addSubview:navigationController.view];
[window makeKeyAndVisible];
You are adding the whole instance of the navigation view controller to the window. 您正在将导航视图控制器的整个实例添加到窗口中。
UIWindow is a descendant of UIView so it just inherits the addSubview method . UIWindow是UIView的后代,因此它仅继承addSubview方法 。 It expects another UIView as parameter.
它期望另一个UIView作为参数。
I would check that your window and it view is returning what you expect via NSLog. 我将检查您的窗口和它的视图是否通过NSLog返回了您期望的结果。 Without seeing the code that creates the window and its view it is hard to tell but I suspect that one of those is not being created correctly.
没有看到创建窗口及其视图的代码,很难说,但是我怀疑其中之一没有正确创建。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.