通过Window-based Application创建项目(一)

通过Window-based Application创建项目

 

第1步:开始一个Window-based Application项目


这里将本实例项目取名为 WinBasedApplication .

 

第2步:创建一个UIViewController 。

 

鼠标选中项目[ WinBasedApplication ]下的目录[Classes],然后点鼠标右键:


 

 

 

选择 [IOS] > [Cocoa Touch Class] > [UIViewController subclass] , 注意在[Options]中的参数均不用选择。


 

将其取名为 FirstViewController .

 

 

至此,现在有4个Class文件,分别是:

 

FirstViewController.h

 

FirstViewController.m

 

WinBasedApplicationAppDelegate.h

 

WinBasedApplicationAppDelegate.m

 

 

第3步:修改  FirstViewController.h

 

#import <UIKit/UIKit.h>

@interface FirstViewController : UIViewController {

UILabel * label ;

UIButton * button ;


}

@property ( nonatomic, retain) UILabel *label;

@property ( nonatomic, retain) UIButton *button;


@end

 

 

第4步:修改  FirstViewController.m

 

 

#import "FirstViewController.h"

@implementation FirstViewController

@synthesize label,button;

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.

/*

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization.

    }

    return self;

}

*/

/*

// Implement loadView to create a view hierarchy programmatically, without using a nib.

- (void)loadView {

}

*/

// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.

- (void )viewDidLoad {

//create the label

CGRect frame=CGRectMake (50 , 30 , 200 , 45 );

label =[[ UILabel alloc] initWithFrame:frame];

label . text = @"This is a label";

//create the button

frame=CGRectMake (50 , 100 , 200 , 45 );

button =[ UIButton buttonWithType: UIButtonTypeRoundedRect];

button .frame =frame;

[ button setTitle: @"OK" forState: UIControlStateNormal];

//add the label and button into current view.

[ self . view addSubview: label ];

[ self . view addSubview: button ];

    [ super viewDidLoad];

}


/*

// Override to allow orientations other than the default portrait orientation.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

    // Return YES for supported orientations.

    return (interfaceOrientation == UIInterfaceOrientationPortrait);

}

*/

- (void )didReceiveMemoryWarning {

    // Releases the view if it doesn't have a superview.

    [ super didReceiveMemoryWarning];

    // Release any cached data, images, etc. that aren't in use.

}

- (void )viewDidUnload {

    [ super viewDidUnload];

    // Release any retained subviews of the main view.

    // e.g. self.myOutlet = nil;

}

- (void )dealloc {

[ label release];

[ button release];


    [super dealloc ];

}

@end

 

 

 

第5步:修改文件  WinBasedApplicationAppDelegate.m

 

#import "WinBasedApplicationAppDelegate.h"

#import "FirstViewController.h"

@implementation WinBasedApplicationAppDelegate

@synthesize window;

FirstViewController *firstViewController;

#pragma mark -

#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {   

    // Override point for customization after application launch.

    firstViewController=[[FirstViewController alloc] initWithNibName:nil bundle:nil];

[self.window addSubview:firstViewController.view];


    [self.window makeKeyAndVisible];

    return YES;

}

- (void)applicationWillResignActive:(UIApplication *)application {

    /*

     Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.

     Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

     */

}

- (void)applicationDidEnterBackground:(UIApplication *)application {

    /*

     Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

     If your application supports background execution, called instead of applicationWillTerminate: when the user quits.

     */

}

- (void)applicationWillEnterForeground:(UIApplication *)application {

    /*

     Called as part of  transition from the background to the inactive state: here you can undo many of the changes made on entering the background.

     */

}

- (void)applicationDidBecomeActive:(UIApplication *)application {

    /*

     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

     */

}

- (void)applicationWillTerminate:(UIApplication *)application {

    /*

     Called when the application is about to terminate.

     See also applicationDidEnterBackground:.

     */

}

#pragma mark -

#pragma mark Memory management

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {

    /*

     Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.

     */

}

- (void)dealloc {

[firstViewController release];

    [window release];

    [super dealloc];

}

@end

 


 

 

最后,运行结果如下图所示:


 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值