iPhone開發(fā)中實現(xiàn)代碼初始化APP中Window
iPhone開發(fā)中實現(xiàn)代碼初始化APP中Window是本文要介紹的內(nèi)容,主要是來學(xué)習(xí)在iphone開發(fā)中如何來初始化APP里的Window,該例介紹如何用代碼這創(chuàng)建iPhone的app的window,這樣可以使我們的app不依賴任何nib文件,完全郵代碼實現(xiàn)。
1、創(chuàng)建基于"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
小結(jié):iPhone開發(fā)中用代碼初始化APP中Window的內(nèi)容介紹完了,希望通過本文的學(xué)習(xí)能對你有所幫助!