////VIEWCONTROLLER.M//01-Addition Calculator////first find the main.m file, then find Appdelegate, then find main inteferce main interactive storyboard, then load the controller with the arrow pointing, then load the view inside the controller. //Connect: Control-drag over and configure. //class Extension: Private properties and methods. #import "ViewController.h"@interfaceViewcontroller () @property (weak, nonatomic) Iboutlet Uitextfield*Num1textfield, @property (weak, nonatomic) Iboutlet Uitextfield*Num2textfield, @property (weak, nonatomic) Iboutlet UILabel*ResultLabel;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; Self.num1TextField.placeholder=@"dddd";}-(ibaction) sum {//1. Get two stringsNSString *sum1string =Self.num1TextField.text; NSString*sum2string =Self.num2TextField.text; //Judging if(Sum1string.length = =0) { /*//Create object Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "input wrong" message:@ "Please enter first number" delegate : nil cancelbuttontitle:@ "I know" otherbuttontitles:nil, nil]; Show [Alertview show]; */[self showinfo:@"Please enter the first number"]; return; } if(Sum2string.length = =0) { /*//Create object Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "input wrong" message:@ "Please enter second number" delegate : nil cancelbuttontitle:@ "I know" otherbuttontitles:nil, nil]; Show [Alertview show]; */[self showinfo:@"Please enter a second number"]; return; } //2. Turn the string into a numeric valueNsinteger sum1 =[sum1string IntegerValue]; Nsinteger sum2=[sum2string IntegerValue]; //3. AddNsinteger result = Sum1 +sum2; //4. Display ResultsSelf.resultLabel.text = [NSString stringWithFormat:@"%zd", result];}//ZD is an unsigned integral type- (void) Showinfo: (NSString *) info{//Creating ObjectsUialertview *alertview = [[Uialertview alloc] Initwithtitle:@"wrong input"Message:infoDelegate: Nil Cancelbuttontitle:@"Yes, I know."Otherbuttontitles:nil, nil]; //Show[Alertview show];}@end
ios5--Calculator