I have an iphone application in which i have two text fields and i have four methods to call on those textfields but problem is that when i change the values of textfield one in second method same value is shown in the first methods while loading.
-(void)textFieldTextDidChangeOneF:(UITextField*)tf{
NSLog(@"Testing Successful Fatal One");
appDelegate.p_Fatal_Yes_NV_InModel = [[textFieldOne text] floatValue];
appDelegate.p_Fatal_No_NV_InModel=100-appDelegate.p_Fatal_Yes_NV_InModel;
textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_Fatal_No_NV_InModel];
NSCharacterSet * set = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789."] invertedSet];
NSString*string=textFieldOne.text;
if ([string rangeOfCharacterFromSet:set].location != NSNotFound) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Warning" message:@"Only a number can be entered into this input field " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
[alert release];
textFieldOne.text=@"";
}
NSLog(@"Fata Data %.2f",appDelegate.p_Fatal_Yes_NV_InModel);
}
I am changing value in this method but also values changes I think problem may calling different methods on same textfield.
here is the code link for complete code
I have two textfields but i am calling four methods on them
Try Using tag
property on UITextField
.
First assign tags to your TextFields programmatically or in xib if you have. Example
[txtFieldOne setTag:100];
[txtFieldTwo setTag:101];
Then differentiate action on your text field using tag like
-(void)textFieldTextDidChangeOneF:(UITextField*)tf
{
switch (tf.tag) {
case 100:
NSLog(@"action on text field one");
break;
case 101:
NSLog(@"action on text field two");
break;
default:
break;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.