objective c - 3 text boxes and a calculate button -


i have 3 text boxes , calculate button, how can tell button witch text box selected , convert number other text boxes, have tagged text boxes 1, 2 , 3, new , green in programming great. code

- (ibaction)calculate:(id)sender {     nsnumberformatter *numberformatter = [[nsnumberformatter alloc] init];      float = [[numberformatter numberfromstring:_barrels.text] floatvalue];     float b = [[numberformatter numberfromstring:_gallons.text] floatvalue];     float c = [[numberformatter numberfromstring:_liters.text] floatvalue];       _barrels.text = [[nsstring alloc]initwithformat:@"% .2f", a];     _gallons.text = [[nsstring alloc]initwithformat:@"% .2f", * 42];     _liters.text = [[nsstring alloc]initwithformat:@"% .2f", * 159];      _barrels.text = [[nsstring alloc]initwithformat:@"% .2f", b * .0238];     _gallons.text = [[nsstring alloc]initwithformat:@"% .2f", b];     _liters.text = [[nsstring alloc]initwithformat:@"% .2f", b * 3.785];      _barrels.text = [[nsstring alloc]initwithformat:@"% .2f", c * .0063];     _gallons.text = [[nsstring alloc]initwithformat:@"% .2f", c * .264];     _liters.text = [[nsstring alloc]initwithformat:@"% .2f", c];      switch ([sender tag]) {         case 1:             [_barrels resignfirstresponder];             [_gallons resignfirstresponder];             [_liters resignfirstresponder];             break;         default:             break;     }  

take variable/flag in viewcontroller.h file store last selected textfield

#import <uikit/uikit.h>  @interface viewcontroller : uiviewcontroller<uitextfielddelegate> {     int textfieldflag; }  @end 

in viewcontroller.m file implement textfielddelegate method

-(void)textfielddidbeginediting:(uitextfield *)textfield  {          textfieldflag=textfield.tag; } 

then in ur

 - (ibaction)calculate:(id)sender {    //above code....         if(textfieldflag==1){     _barrels.text = [[nsstring alloc]initwithformat:@"% .2f", a];     _gallons.text = [[nsstring alloc]initwithformat:@"% .2f", * 42];     _liters.text = [[nsstring alloc]initwithformat:@"% .2f", * 159];    } if(textfieldflag==2){     _barrels.text = [[nsstring alloc]initwithformat:@"% .2f", b * .0238];     _gallons.text = [[nsstring alloc]initwithformat:@"% .2f", b];     _liters.text = [[nsstring alloc]initwithformat:@"% .2f", b * 3.785];    } if(textfieldflag==3){     _barrels.text = [[nsstring alloc]initwithformat:@"% .2f", c * .0063];     _gallons.text = [[nsstring alloc]initwithformat:@"% .2f", c * .264];     _liters.text = [[nsstring alloc]initwithformat:@"% .2f", c];    }     //below code... 

}

use textfieldflag accordingly.

textfieldflag contain flag last textfield selected/edited


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -