ios5--Calculator

Source: Internet
Author: User

////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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.