Hello World

来源:互联网 发布:php网页输出原代码 编辑:程序博客网 时间:2024/06/16 11:37

仅是学习过程的笔记,用于定期复习。


1、打开Xcode,进入File-New-New Project。在弹出的对话框内,选择IOS Application,在右侧列表内选择“Single View Application”。


2、点击“MainStoryboard.storyboard“,在上面放置一个button,label,text 。


3、打开ViewController.h,加入:

@property(nonatomic,retain) IBOutlet UILabel* lblHello;
@property(nonatomic,retain) IBOutlet UITextField* tfInput;

-(IBAction)buttonPressed:(id)sender;


4、打开ViewController.m,在行“@interface ViewController : UIViewController”下边加入:

@synthesize lblHello;
@synthesize tfInput;

-(IBAction)buttonPressed:(id)sender
{
    //lblHello.text = @"Hello World";
    lblHello.text = self.tfInput.text;
}


5、修改- (void)viewDidUnload,加入两个属性变量的内存释放
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
    self.lblHello = nil;
    self.tfInput = nil;
}

6、关联代码与控件映射关系(才开始学,还不知道正确的术语),点击视图上的Lable控件,右键单击弹出菜单选择“referencing outlets",左键点击那个小“+”号,拖动到视图任意处,然后松开左键,会有个列表弹出来,你可以选择lblHello,将控件Lable与属性lblHello关连起来。其它两个控件依此类推。


7、至此基本完成,运行程序试试。