ios - textFieldShouldReturn 没有被调用(textField 以编程方式加载)
<p><p>我目前正在以编程方式加载 -<code>UITextField</code> 并尝试在单击“搜索”后使键盘向下。</p>
<p>我将 .m 文件中的 <code>-UITextFeild</code> 声明为
<code>UITextField *searchTextField;</code></p>
<p>在 .h 文件中,我确实声明了 <code>-UITextField</code> 的委托(delegate)</p>
<pre><code>@interface firstChannel : UIViewController<LBYouTubePlayerControllerDelegate, UITableViewDelegate,UITableViewDataSource, NSXMLParserDelegate, UITextFieldDelegate, AVPlayerItemOutputPullDelegate>{
</code></pre>
<p>这就是我以编程方式添加 UITextField 的方式。</p>
<pre><code> searchTextField = [ initWithFrame:CGRectMake(10, -26, 300, 30)];
searchTextField.borderStyle = UITextBorderStyleRoundedRect;
searchTextField.font = ;
searchTextField.autocorrectionType = UITextAutocorrectionTypeNo;
searchTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
searchTextField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
searchTextField.placeholder = @"Search on the Channel";
searchTextField.borderStyle = UITextBorderStyleNone;;
searchTextField.textAlignment = UITextAlignmentCenter;
searchTextField.center = CGPointMake(160, 43);
searchTextField.textColor = ;
searchTextField.clearButtonMode = UITextFieldViewModeNever;
searchTextField.returnKeyType = UIReturnKeySearch;
;
;
;
</code></pre>
<p>我在 <code>-viewDidLoad</code></p> 中添加了委托(delegate)
<pre><code>searchTextField.delegate = self;
</code></pre>
<p>但是,当我点击键盘上的“搜索”时,什么也没有发生。我不确定为什么会这样</p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>在创建和设置文本字段后调用 <code>searchTExtField.delegate</code>。</p></p>
<p style="font-size: 20px;">关于ios - textFieldShouldReturn 没有被调用(textField 以编程方式加载),我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/18602104/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/18602104/
</a>
</p>
页:
[1]