iOS Practice addition Calculator

Source: Internet
Author: User

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

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.