菜鸟教程小白 发表于 2022-12-11 20:35:01

ios - 触摸文本字段时创建操作


                                            <p><p>我需要在触摸文本字段时执行操作。我已经导入了 Material 来为 UI 设计动画提供一些效果。我需要在触摸文本字段时显示 View 。但我收到错误:无法识别的选择器发送到实例 0x7fed2b046800'
*** 首先抛出调用栈:</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您不必添加目标(而且添加选择器不是正确的方法)</p>

<pre><code> self.dobField.addTarget(self, action:Selector((&#34;textFieldDidBeginEditing&#34;)), for: UIControlEvents.editingDidBegin)
</code></pre>

<p>你只需要</p>

<pre><code>self.dobField.delegate = self
</code></pre>

<p>与</p>

<pre><code>func textFieldDidBeginEditing(_ textField: UITextField){}
</code></pre>

<p>//</p>

<p>正确的选择器是</p>

<pre><code>self.dobField.addTarget(self, action:#selector(someMethod), for: UIControlEvents.editingDidBegin)
</code></pre>

<p>与</p>

<pre><code>@objc func someMethod(_ textField: UITextField){}
</code></pre>

<p>顺便说一句,您已经符合 <code>UITextFieldDelegate</code></p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 触摸文本字段时创建操作,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/52311388/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/52311388/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 触摸文本字段时创建操作