iPhone开发中实现代码初始化APP中Window是本文要介绍的内容,主要是来学习在iphone开发中如何来初始化APP里的Window,该例介绍如何用代码这创建iPhone的app的window,这样可以使我们的app不依赖任何nib文件,完全邮代码实现。
1、创建基于"window-based application"的新项目"CodingWindowDemo";
2、删除MainWindow.xib文件;
3、删除CodingWindowDemo-Info.plist文件中"Main nib file base name"行;
4、修改main.m代码:
- 将原来行:
- int retVal = UIApplicationMain(argc, argv, nil, nil);
- 改为:
- int retVal = UIApplicationMain(argc, argv, nil, @"CodingWindowDemoAppDelegate");
5、修改CodingWindowDemoAppDelegate.h后代码如下:
- #import <UIKit/UIKit.h>@interface CodingWindowDemoAppDelegate : NSObject <UIApplicationDelegate> {
- UIWindow *window;}//@property (nonatomic, retain) IBOutlet UIWindow *window;@end
6、修改CodingWindowDemoAppDelegate.m后代码如下:
- #import "CodingWindowDemoAppDelegate.h"
- @implementation CodingWindowDemoAppDelegate//
- @synthesize window;#pragma mark-
- #pragma mark Application lifecycle
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
- // Override point for customization after application launch.
- window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
- window.backgroundColor = [UIColor blueColor];
- //这里可以加入加载view的代码
- //...
- [window makeKeyAndVisible];
- return YES;
- }#pragma mark -
- #pragma mark Memory management
- - (void)dealloc {
- [window release];
- [super dealloc];
- }
- @end
小结:iPhone开发中用代码初始化APP中Window的内容介绍完了,希望通过本文的学习能对你有所帮助!