我的iphone开发学习笔记(一)创建view_based_application
2011-11-29 23:03
579 查看
对于刚刚开始学习的同学,跟着练习是最好的学习方法。一次编码胜过通读全书。
一。打开xcode, 选择创建view_based_application, 输入项目名称HelloNum
二。 在HelloNumControllerVier.h
定义三个控件
1. UILabel *userOutput
2. UITextField *userInput;
3. UIButton *button
代码如下:
三。打开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.m
添加@synthesize userInput, userOutput;
完成方法 setOutput:(id)sender
代码如下
第一个简单项目就这样完成了。
小结下:
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界面处理不太一样。
洗洗睡了。
一。打开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界面处理不太一样。
洗洗睡了。
相关文章推荐
- delphi.net开发学习笔记(2),Application、Session、ViewState、Cookies状态以及变量处理
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- 我的iphone开发学习笔记(三)使用UISlide, UIImageView及动画
- iPhone开发学习笔记007——Xcode4.2下iPhone多视图开发(自已创建MainWindow.xib和不用MainWindow.xib两种实现)
- iPhone开发学习笔记007——Xcode4.2下iPhone多视图开发(自已创建MainWindow.xib和不用MainWindow.xib两种实现)
- iPhone开发学习笔记[3/50]-使用工具栏创建简单的多视图应用程序
- IPhone 开发笔记WebView 学习
- iPhone开发学习笔记--UIScrollView
- iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view
- iPhone开发学习笔记007——Xcode4.2下iPhone多视图开发(自已创建MainWindow.xib和不用MainWindow.xib两种实现)
- 我的iphone开发学习笔记(六): 使用选项卡栏管理多视图界面
- iphone/ipad关于size, frame and bounds总结和UIScroll view学习笔记
- Qt Model/View 学习笔记 (四) 创建新的Models
- iphone 开发学习笔记一
- Visionpro学习笔记 :QuickBuild-Based Application Run-Once Button
- ios学习--iphone开发笔记和技巧总结(原址持续更新)
- IPHONE应用开发 - ViewControl 与 xib 学习心得
- ((ios开发学习笔记五))手动创建Tab Bar Controller 程序
- iphone开发学习笔记-2