我的iphone开发学习笔记(一)创建view_based_application

对于刚刚开始学习的同学,跟着练习是最好的学习方法。一次编码胜过通读全书。

一。打开xcode, 选择创建view_based_application, 输入项目名称HelloNum

二。 在HelloNumControllerVier.h 

         定义三个控件

        1. UILabel *userOutput

        2. UITextField *userInput;

        3. UIButton *button

代码如下:

#import <UIKit/UIKit.h>

@interface HelloNumViewController : UIViewController {
	IBOutlet UILabel *userOutput;
	IBOutlet UITextField *userInput;
}


-(IBAction)setOutput:(id)sender;

@end

三。打开resource文件夹中HelloNumViewController.xib

        1. 打开其中的view

        2. 打开Tools菜单,选择Library

         3. 1 取出UILabel, 拖到view, 修改文字

         3.2  取出UILabel, 拖到view,   修改文字 Noun Goes Here

         3.3 取出 UITextField, 拖到view

        3.4. 取出Round Rect Button,  拖到view, 修改文字 Set Label


四。 关键步骤,连接

          打开HelloNumViewController.xib

          4.1 选择File's Owner, 按住control, 链接到Label(Num goes here),选择userOutput, ok

           4. 2 选择File's Owner, 按住control, 链接到TextField,选择userInput, ok

          4.3 选择RoundButton, 按住control, 选择File's Owner, 选择setOutput方法, ok


五, 回到HelloNumViewController.h

        添加ui控件的@property属性

             

//
//  HelloNumViewController.h
//  HelloNum
//
//  Created by 旭 陈 on 11-11-30.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface HelloNumViewController : UIViewController {
	IBOutlet UILabel *userOutput;
	IBOutlet UITextField *userInput;
}

@property(nonatomic,retain)UITextField *userInput;
@property(nonatomic,retain)UILabel *userOutput;


-(IBAction)setOutput:(id)sender;

@end


六。 HelloNumViewController.m 

        添加@synthesize userInput, userOutput;

        完成方法 setOutput:(id)sender

       代码如下

        

//
//  HelloNumViewController.m
//  HelloNum
//
//  Created by 旭 陈 on 11-11-30.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import "HelloNumViewController.h"

@implementation HelloNumViewController

@synthesize userInput, userOutput;


/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        // 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 {
    [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 {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}

-(IBAction)setOutput:(id)sender{
	userOutput.text = userInput.text;
}

@end

第一个简单项目就这样完成了。

小结下:

1。 创建基于view_base_application

2.    view视图添加需要的uilabel, uitextfield, button

3.    .h 声明刚才的ui控件

4. 连接files Owner 与输出控件

     连接 button的方法和file's Owner

5. 编写@property, @synthesize

6.  完成setOutput:(id)sender

      userOutput.text = userInput.text;




多多练习,特别是ui 和 file‘s Owner的连接,与传统的android界面处理不太一样。

洗洗睡了。

        

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值