gpt4 book ai didi

iphone - 如何在iphone app中自动调用UITextField的textDidChange方法

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:46:41 26 4
gpt4 key购买 nike

我在 iPhone 应用程序中工作,其中有文本字段,我希望当任何文本发生更改时,应自动调用以下方法。

   -(void)textFieldTextDidChangeOneCI:(UITextField*)tf{



NSLog(@"Testing Successful Value %.2f",appDelegate.p_ClinInf_Yes_V_InModel);
appDelegate.p_ClinInf_Yes_NV_InModel = [[textFieldOne text] floatValue];

appDelegate.p_ClinInf_No_NV_InModel=100-appDelegate.p_ClinInf_Yes_NV_InModel;

textFieldTwo.text=[NSString stringWithFormat:@"%.2f",appDelegate.p_ClinInf_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(@"Testing Successful CI Data %.2f",appDelegate.p_ClinInf_Yes_NV_InModel);

}

目前我称之为

使用

    [textFieldOne addTarget:self action:@selector(textFieldTextDidChangeOneCI:) forControlEvents:UIControlEventEditingChanged];

最佳答案

试试这个

 - (void)viewDidLoad
{
[super viewDidLoad];

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(textFieldTextDidChangeOneCI:)
name:UITextFieldTextDidChangeNotification
object:textfield];
}

也修改你的方法

 -(void)textFieldTextDidChangeOneCI:(NSNotification *)notification
{
UITextField *textfield=[notification object];
NSLog(@"%@",textfield.text);

}

关于iphone - 如何在iphone app中自动调用UITextField的textDidChange方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16684916/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com