首先建一个空的项目:
点击next,并添其项目名称UIDay_01,所以的勾都不选。
新建UIViewController文件:
新建xib文件:
建完xib文件并打开,并与上面的UIViewControler类关联,还有view关联;
接下来是在AppDelegate.h并.m里添写代码:
#import <UIKit/UIKit.h>//包含类
@class DemoViewController;//声明类
@interface AppDelegate : UIResponder <UIApplicationDelegate>{
//定义一个程序 显示 窗口的对象
UIWindow *window;
//加入视图控制 实际 变量的对象
DemoViewController *iDemoView;
}
//此处@Property声明程序的属性,并且加入在前面@interface中指定的相同对象
//其中nonatomic是使用单线程机制减少系统资源使用,并将更改方法和修改方法生成在Property(属性)
@property (strong, nonatomic) UIWindow *window;
@property (nonatomic,retain)DemoViewController *iDemoView;
@end
#import "AppDelegate.h"
#import "DemoViewController.h"
@implementation AppDelegate
@synthesize iDemoView=_iDemoView;
@synthesize window = _window;
//内存清理
- (void)dealloc
{
[_window release];
_iDemoView=nil;
[super dealloc];
}
//在应用程序开始后重新自定义用户化点,在显示窗口加入ViewController的显示视图
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.iDemoView=[[[DemoViewController alloc]initWithNibName:@"DemoViewController" bundle:nil]autorelease];
self.window.backgroundColor = [UIColor whiteColor];
//在显示窗口子视图加入iDemoView视图
[self.window addSubview:self.iDemoView.view];
//使被使用对象的主窗口显示至屏幕的最前端
[self.window makeKeyAndVisible];
return YES;
}