iphone - 如何在iphone应用程序中自动调用UITextField的textDidChange方法
<p><p>我在 iphone 应用程序中工作,其中有我想要的文本字段,当任何文本发生更改时,应自动调用以下方法。</p>
<pre><code> -(void)textFieldTextDidChangeOneCI:(UITextField*)tf{
NSLog(@"Testing Successful Value %.2f",appDelegate.p_ClinInf_Yes_V_InModel);
appDelegate.p_ClinInf_Yes_NV_InModel= [ floatValue];
appDelegate.p_ClinInf_No_NV_InModel=100-appDelegate.p_ClinInf_Yes_NV_InModel;
textFieldTwo.text=;
NSCharacterSet * set = [ invertedSet];
NSString*string=textFieldOne.text;
if (.location != NSNotFound) {
UIAlertView * alert = [ initWithTitle:@"Warning" message:@"Only a number can be entered into this input field " delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
;
;
textFieldOne.text=@"";
}
NSLog(@"Testing Successful CI Data%.2f",appDelegate.p_ClinInf_Yes_NV_InModel);
}
</code></pre>
<p>目前我正在调用它</p>
<p>使用</p>
<pre><code> ;
</code></pre></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>试试这个</p>
<pre><code> - (void)viewDidLoad
{
;
[
addObserver:self
selector:@selector(textFieldTextDidChangeOneCI:)
name:UITextFieldTextDidChangeNotification
object:textfield];
}
</code></pre>
<p>同时修改你的方法</p>
<pre><code> -(void)textFieldTextDidChangeOneCI:(NSNotification *)notification
{
UITextField *textfield=;
NSLog(@"%@",textfield.text);
}
</code></pre></p>
<p style="font-size: 20px;">关于iphone - 如何在iphone应用程序中自动调用UITextField的textDidChange方法,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/16684916/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/16684916/
</a>
</p>
页:
[1]