我有SingleView
个申请。现在我想在我的项目中添加mainwindow
。
如何将window
添加到我的项目中?
提前致谢。
答案 0 :(得分:1)
首先将您的LoginViewController
添加为self.window.rootViewController
,例如
在Appdelegate.h
文件中添加此代码
#import <UIKit/UIKit.h>
#import "AppDelegate.h"
@interface AppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
}
@property (nonatomic, retain) UIWindow *window;
@end
在Appdelegate.m
文件中添加此代码
(这里我也添加了UINavigationController)
@synthesize window=_window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
LoginViewController *loginViewController = [[LoginViewController alloc] init];
UINavigationController *loginNVController = [[UINavigationController alloc] initWithRootViewController:loginViewController];
loginNVController.navigationBarHidden = YES;
self.window.rootViewController = loginNVController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
或直接添加
点击此链接添加window.xib
。
Check this link
答案 1 :(得分:0)
如果您选择了单一视图应用程序。您可以根据视图提供xib名称。从某种意义上讲,这更为一般。如果您选择了空应用程序,请转到xcode项目并添加新文件。它从UIViewController扩展。
无法在任何.xib文件中引用AppDelegate。 main方法将实例化AppDelegate对象,然后AppDelegate对象将实例化其他视图控制器。
您可以阅读更多Apple文档。
由于 临空