[英]how to call different methods on two UITextfields in iphone application
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. 我有一个iphone应用程序,其中我有两个文本字段,我有四种方法来调用这些文本字段,但问题是,当我更改文本字段的值时,第二种方法在加载时在第一种方法中显示相同的值。
-(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 我有两个文本域,但我在它们上面调用了四种方法
http://paste.bradleygill.com/index.php?paste_id=4011 http://paste.bradleygill.com/index.php?paste_id=4011
Try Using tag
property on UITextField
. 尝试在UITextField
上使用tag
属性。
First assign tags to your TextFields programmatically or in xib if you have. 首先以编程方式为您的TextField分配标签,如果有,则为xib分配标签。 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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.