//
// LCViewController.m
// calculator
//
// Created by lichan on 13-12-3.
// Copyright (c) 2013 year com.lichan. All rights reserved.
// #import "LCViewController.h" static int lastKey = -1; @interface LCViewController () @end @implementation LCViewController #pragma mark numberButtonPressed method - (IBAction)buttonPressed:(id)sender // Digital display connection button
{ UIButton *tempButton = (UIButton *)sender; NSString *tempNumber = [tempButton titleLabel].text;// obtain button Of title value , In order to facilitate the textField Show [_textField setText:[NSString stringWithFormat:@"%@%@",_textField.text,tempNumber]]; //textfield The connection of strings on , In order to form a string self.temp = _textField.text; // NSLog(@" floating-point :%f",[self.temp floatValue]); } - (IBAction)backButtonPressed:(id)sender { if (self.temp) {
self.temp = [self.temp substringToIndex:self.temp.length-1]; [_textField setText:self.temp];
NSLog(@"new Temp:%@",self.temp);
} } - (IBAction)opreatePressed:(id)sender // Operator button
{
[_textField setText:@""];
if (!self.result)
{
self.result = self.temp;
self.temp = nil;
} self.num1 = [self.result floatValue];
self.num2 = [self.temp floatValue];
NSInteger opreateTag = [sender tag];
switch (opreateTag) {
case 1:
{
lastKey = 1;
[self plusOperatorSymbol];
break;
}
case 2:
{
lastKey = 2;
[self subOperatorSymbol];
break;
}
case 3:
{ lastKey = 3;
[self multiOperatorSymbol];
break;
}
case 4:
{
lastKey = 4;
[self divOperatorSymbol];
break;
}
case 5:
{ if (lastKey == 1)
{
[self plusOperatorSymbol]; }else if(lastKey == 2)
{
[self subOperatorSymbol]; }else if(lastKey == 3)
{
[self multiOperatorSymbol]; }else if(lastKey == 4)
{
lastKey = 4; [self divOperatorSymbol];
} [_textField setText:self.result];
break;
} case 6:
{
self.result = nil;
self.temp = nil; break; } default:
break;
} } #pragma mark Operation symbol method - (void)plusOperatorSymbol
{ if (self.temp != nil)
{
float resultNum = _num1 + _num2; self.result = [NSString stringWithFormat:@"%f",resultNum]; self.temp = nil;
} } - (void)subOperatorSymbol
{ if (self.temp != nil)
{
float resultNum = _num1 - _num2; self.result = [NSString stringWithFormat:@"%f",resultNum]; self.temp = nil;
} } - (void)multiOperatorSymbol
{ if (self.temp != nil)
{
float resultNum = _num1 * _num2; self.result = [NSString stringWithFormat:@"%f",resultNum]; self.temp = nil;
} } - (void)divOperatorSymbol
{ if (self.temp != nil)
{
float resultNum = _num1 / _num2; self.result = [NSString stringWithFormat:@"%f",resultNum]; self.temp = nil;
} } #pragma mark System method - (void)dealloc
{
[_textField release]; [_result release];
[_numberString release];
[_temp release]; [super dealloc];
} - (void)viewDidLoad
{
[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

The simplest priority

.h

//
// LCViewController.h
// calculator
//
// Created by lichan on 13-12-3.
// Copyright (c) 2013 year com.lichan. All rights reserved.
// #import <UIKit/UIKit.h> @interface LCViewController : UIViewController
@property (retain, nonatomic) IBOutlet UITextField *textField; @property (copy,nonatomic)NSString *numberString; @property (copy,nonatomic)NSString *result; @property (copy,nonatomic)NSString *temp; @property (nonatomic) float num1;
@property (nonatomic) float num2; - (IBAction)buttonPressed:(id)sender; - (IBAction)backButtonPressed:(id)sender; -(IBAction)opreatePressed:(id)sender; @end

.m file

//
// LCViewController.m
// calculator
//
// Created by lichan on 13-12-3.
// Copyright (c) 2013 year com.lichan. All rights reserved.
// #import "LCViewController.h" static int lastKey = -1; @interface LCViewController () @end @implementation LCViewController #pragma mark numberButtonPressed method - (IBAction)buttonPressed:(id)sender // Digital display connection button
{ UIButton *tempButton = (UIButton *)sender; NSString *tempNumber = [tempButton titleLabel].text;// obtain button Of title value , In order to facilitate the textField Show [_textField setText:[NSString stringWithFormat:@"%@%@",_textField.text,tempNumber]]; //textfield The connection of strings on , In order to form a string self.temp = _textField.text; // NSLog(@" floating-point :%f",[self.temp floatValue]); } - (IBAction)backButtonPressed:(id)sender { if (self.temp) {
self.temp = [self.temp substringToIndex:self.temp.length-1]; [_textField setText:self.temp];
NSLog(@"new Temp:%@",self.temp);
} } - (IBAction)opreatePressed:(id)sender // Operator button
{
[_textField setText:@""];
if (!self.result)
{
self.result = self.temp;
self.temp = nil;
} self.num1 = [self.result floatValue];
self.num2 = [self.temp floatValue];
NSInteger opreateTag = [sender tag];
switch (opreateTag) {
case 1:
{
lastKey = 1;
[self plusOperatorSymbol];
break;
}
case 2:
{
lastKey = 2;
[self subOperatorSymbol];
break;
}
case 3:
{ lastKey = 3;
[self multiOperatorSymbol];
break;
}
case 4:
{
lastKey = 4;
[self divOperatorSymbol];
break;
}
case 5:
{ if (lastKey == 1)
{
[self plusOperatorSymbol]; }else if(lastKey == 2)
{
[self subOperatorSymbol]; }else if(lastKey == 3)
{
[self multiOperatorSymbol]; }else if(lastKey == 4)
{
lastKey = 4; [self divOperatorSymbol];
} [_textField setText:self.result];
break;
} case 6:
{
self.result = nil;
self.temp = nil; break; } default:
break;
} } #pragma mark Operation symbol method - (void)plusOperatorSymbol
{ if (self.temp != nil)
{
float resultNum = _num1 + _num2; self.result = [NSString stringWithFormat:@"%f",resultNum]; self.temp = nil;
} } - (void)subOperatorSymbol
{ if (self.temp != nil)
{
float resultNum = _num1 - _num2; self.result = [NSString stringWithFormat:@"%f",resultNum]; self.temp = nil;
} } - (void)multiOperatorSymbol
{ if (self.temp != nil)
{
float resultNum = _num1 * _num2; self.result = [NSString stringWithFormat:@"%f",resultNum]; self.temp = nil;
} } - (void)divOperatorSymbol
{ if (self.temp != nil)
{
float resultNum = _num1 / _num2; self.result = [NSString stringWithFormat:@"%f",resultNum]; self.temp = nil;
} } #pragma mark System method - (void)dealloc
{
[_textField release]; [_result release];
[_numberString release];
[_temp release]; [super dealloc];
} - (void)viewDidLoad
{
[super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib.
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

[ Classroom practice and projects ]IOS Can only carry out simple addition, subtraction, multiplication and division, no priority calculator more related articles

  1. [ Classroom practice and projects ]IOS Priority calculator

    This calculator is mainly implemented by using arrays . Although no Prefix suffix expression is used , But it's a way o. .h file // // LCViewController.h // Priority calculator // // Cr ...

  2. [ Classroom practice and projects ] mobile phone QQ client --4 period (SQLite The addition of , register , Retrieve , Modification of login interface ): Set up about QQ Registration class , Use SQLite For storage ,

    After the unremitting efforts of yesterday afternoon and this morning , It's finally passed SQLite Learning from . Let's define a concept about SQLIte The wrapper class , It's convenient for me to register with users in the back , User password Retrieval , And the use of the login interface 1. First, let's look at the use ...

  3. [ Classroom practice and projects ]NavigationController And TabBarController Comprehensive use and error prone point analysis of ( Include message reminders ,app to update )

    State : We are using tabbarController When , We will always be with you NavagationController unite . But what is it like when it is not united pool In the case? ? We just TabBarCont ...

  4. 2016-2017-2 《Java Programming 》 Classroom practice projects

    Catalog Basic tools Basic content Hello World and Module decomposition Use of arrays Command line arguments recursive Branch statement String The use of the class Class definition and testing polymorphic IO And anomalies database Network and security Data structure application And ...

  5. 《Java Programming 》 Classroom practice projects After class learning summary

    <Java Programming > Classroom practice projects After class learning summary String The use of the class (sort) Catalog Linux command (sort) Classroom practice After thinking about Thinking after learning the teacher's code :int And Integer ...

  6. 《Java Programming 》 Classroom practice projects - Class definition

    <Java Programming > Class practice project class definition After class learning summary Catalog change Class definition experiment requirements Classroom practice results After thinking about change Changed the overall layout of the blog , In the past, it was very rash to paste a code and a picture , This time, the layout and content have been modified . ...

  7. 20155308 2016-2017-2《Java Programming 》 Classroom practice projects

    20155308 2016-2017-2<Java Programming > Classroom practice projects stay java.lang There is... In the bag String.split() Method , The return is an array I use some in the application , Just to summarize , only ...

  8. 《Java Programming 》 Classroom practice projects - Command line arguments

    <Java Programming > Classroom practice projects After class learning summary Catalog change Command line parameter experiment requirements Classroom practice results After thinking about change Changed the overall layout of the blog , In the past, it was very rash to paste a code and a picture , This time, the layout and content have been modified . added ...

  9. 《Java Programming 》 Classroom practice projects -mini dc

    <Java Programming > Classroom practice projects - Postfix expression After class learning summary Catalog change mini dc The experimental requirements Introduction to suffix expressions Classroom practice results After thinking about change Changed the overall layout of the blog , Changed the previous paste a screenshot paste generation ...

Random recommendation

  1. Nancy Study - Identity Authentication (Basic Authentication) Continue to cross platform

    Open source Sample code :https://github.com/linezero/NancyDemo I'll talk about it Nancy The advanced part of , Now let's learn Nancy Identity authentication . This article mainly explains Basic Authentic ...

  2. MySQL appear Waiting for table metadata lock The reasons and solutions

    from :http://ctripmysqldba.iteye.com/blog/1938150 ( Modified ) MySQL It's going on alter table etc. DDL In operation , Sometimes there will be Waiting for tab ...

  3. event Event learning section

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. Android Authoritative programming guide reading notes (1-2 Chapter )

    Chapter one Android First experience of application 1.4 User interface design <?xml version="1.0" encoding="utf-8"?> ADT21 Development Edition ...

  5. jQuery How to realize text display 2s, disappear 0.5s, Re display 2s, Disappear again 0.5s, In this cycle

    <div style="display: none;" id='divTestDisplay'> The text I want to display </div> window.onload = ...

  6. scrapy_items

    Why items? When there's a lot of data , There is no unified data management , Unified formatting is troublesome items In addition to the ability to add fields , What else can be done ? 1.  Pre treatment 2. From the items The data out there is processed 3. write sql Sentence logic ...

  7. ASP.NET Aries Advanced development tutorial :Excel Rules for importing configuration ( Next )

    Preface : The first two articles are about the process , There are some configuration details , No details , Here is a supplement to . 1.Excel Configuration item Starting row index . The number of column headers across rows : For custom Excel Import template ( Sometimes templates are provided by customers , The template rules are messy ) ...

  8. hdu1598 find the most comfortable road ( enumeration )+【 Union checking set 】

    < Topic link > The main idea of the topic : XX Star has many cities , There is a strange highway between cities SARS(Super Air Roam Structure--- Super Air roaming structure ) To communicate , Every one of them SARS All right, driving in ...

  9. Eclipse The code cursor in becomes a black block

    In the past, I used to write programs, but I didn't know the key on the keyboard , Or those combination keys , bring Eclipse The code cursor in becomes a black block : In this state , The cursor is not moving , You can only write code all the way back , I don't want to " | & ...

  10. LibreOJ #6013. 「 Network flow 24 topic 」 Load balancing Minimum cost and maximum flow The problem of supply balance

    #6013. 「 Network flow 24 topic 」 Load balancing Memory limit :256 MiB The time limit :1000 ms Standard input and output Topic type : Traditional evaluation methods : Text comparison Uploaded by : anonymous Submit record statistics, discuss test data   Title Description ...