我在 iphone 应用程序中工作,其中有我想要的文本字段,当任何文本发生更改时,应自动调用以下方法。
-(void)textFieldTextDidChangeOneCIUITextField*)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 actionselector(textFieldTextDidChangeOneCI forControlEvents:UIControlEventEditingChanged];
试试这个
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter]
addObserver:self
selectorselector(textFieldTextDidChangeOneCI
name:UITextFieldTextDidChangeNotification
object:textfield];
}
同时修改你的方法
-(void)textFieldTextDidChangeOneCINSNotification *)notification
{
UITextField *textfield=[notification object];
NSLog(@"%@",textfield.text);
}
关于iphone - 如何在iphone应用程序中自动调用UITextField的textDidChange方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16684916/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |