Here is the specific code:
ViewController.h
#import <UIKit/UIKit.h>
@interface Viewcontroller:uiviewcontroller
/*
1. Development steps
1. Build the interface
2. Connection
3. Writing code
2.IBAction & Iboutlet
Ibaction is used to establish a relationship with the operation, the ibaction essence is a void, but can be used to connect the = method
Iboutlet is used to establish a relationship with elements on the interface to obtain/modify the properties of the interface control. = @property
3.UIViewController & UIView
Uiviewcontroller is responsible for the control of the program, The Big Butler
UIView is responsible for the display of the interface
4. Lazy loading, lazily loading
Load into memory when needed
Efficiency: Low
Memory consumption: Small
*/
@end
VIEWCONTROLLER.M
#import "ViewController.h"
XCODE5 Start Apple recommends that the property and method statements that are not open to the outside are put in. m
Private extension
@interface Viewcontroller ()
Calculation method
The interface on the left is formerly known as Interface Builder, and in OC It is usually preceded by IB
-(ibaction) compute;
Ctrl+cmd+j = CMD + click
@property (nonatomic,weak) iboutlet Uitextfield *num1;
@property (nonatomic,weak) iboutlet Uitextfield *num2;
@property (nonatomic,weak) iboutlet UILabel *sumlabel;
@end
@implementation Viewcontroller
-(ibaction) Compute
{
1. Get the values in the two text boxes
NSString *str1 = Self.num1.text;
NSString *str2 = Self.num2.text;
2. Add a value
int result = Str1.intvalue + Str2.intvalue;
3. Display the results on the right side of the label
Self.sumLabel.text = [NSString stringwithformat:@ "%d", result];
4. Turn off the keyboard
Who created, who destroyed! Who turned on the keyboard who turned off the keyboard
First Responder, the control that opens the keyboard
[Self.num1 Resignfirstresponder];
[Self.num2 Resignfirstresponder];
Force the keyboard off
[Self.view Endediting:yes];
}
@end
iOS Practice addition Calculator