Program Requirements
Implement click a button to display the current datetime in the corresponding text box (Xcode6.1 version)
Implementing the main steps
-
- Modify interface, Open Main.storyboard, use the Interface Editor (IB) to drag and drop a button and text edit box (View)
-
-
- in the interface Editor (IB) face, hold down CTRL , pull a straight line from the button to the top view control, then select the Button event response function in the list to implement the connection between the button press and the response function. (or click the button, from the toolbar on the right, show the touch up inside in the Connections Inspector list and pull a straight line to the view Control on the top of the window. and select the event response function to ) (pull straight from the interface to view Control )
- Open Interface Editor (IB), from view control pull a straight line to the box, and then select a box variable defined in the list to achieve the link between the Board box and the variable (from the Span style= "font-size:18px" >view control pull Line to interface )
- Implementing logical Code , including setting variables, writing the response function
Sample code
- ViewController.h
viewcontroller.h// 1129_hellowolrd//// Created by God Lin on 14/11/29.// Copyright (c) 2014 Arbboter. All rights reserved.//#import <UIKit/UIKit.h> @interface viewcontroller:uiviewcontroller{ uitextfield* Texttime;} @property (nonatomic, retain) iboutlet uitextfield* texttime;-(ibaction) ONCLICKTIMEBTN: (ID) sender; @end
- Viewcontroller.m
viewcontroller.m// 1129_hellowolrd//// Created by God Lin on 14/11/29.// Copyright (c) 2014 Arbboter. All rights reserved.//#import "ViewController.h" @interface Viewcontroller () @end @implementation Viewcontroller@synthesize texttime;-(ibaction) ONCLICKTIMEBTN: (ID) sender{ if (texttime) { nsdate* date = [NSDate Date]; Texttime.text = [date description]; }} -(void) viewdidload { [super viewdidload]; Do any additional setup after loading the view, typically from a nib.} -(void) didreceivememorywarning { [super didreceivememorywarning]; Dispose of any resources the can be recreated.} @end
Ios-Getting Started example