菜鸟教程小白 发表于 2022-12-13 14:02:02

ios - 应用程序在 ios 中触摸 UITextField 时崩溃


                                            <p><div>
            <aside class="s-notice s-notice__info post-notice js-post-notice mb16"role="status">
      <div class="d-flex fd-column fw-nowrap">
            <div class="d-flex fw-nowrap">
                <div class="flex--item wmn0 fl1 lh-lg">
                  <div class="flex--item fl1 lh-lg">
                        <b>这个问题在这里已经有了答案</b>:
                        
                  <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>问题出在你的名字上:</p>

<pre><code>@property (strong, nonatomic) InputViewController *inputViewController;
</code></pre>

<p>Apple 在 UIResponder 类中添加了一个类似名称的属性:</p>

<pre><code>@property (nonatomic, readonly, retain) UIInputViewController *inputViewController NS_AVAILABLE_IOS(8_0);
</code></pre>

<p>会发生这样的事情:</p>

<ol>
<li>用户点击您的 TextField。</li>
<li>由于名称相似的属性,UIKit 框架将您的自定义 InputViewController 误认为是 <code>UIInputViewController</code> 类型的实例。</li>
<li>UIKit 尝试在 InputViewController 的实例上调用 <code>UIInputViewController</code> 的 <code>keyboard</code> 方法。 </li>
<li><code>keyboard</code> 方法在 InputViewController 上不存在,因为它不是 <code>UIInputViewController</code> 的实例。</li>
<li>你得到一个无法识别的选择器被发送到你的 ViewController 的错误,因为你的 ViewController 中没有这样的方法并且应用程序正确地崩溃了。 </li>
</ol>

<p>更改该属性的名称,您应该没问题。 </p>

<p>更多详情,见<a href="https://stackoverflow.com/users/860000/brian-nickel" rel="noreferrer noopener nofollow">Brian Nickel</a>的回答<a href="https://stackoverflow.com/questions/27930743/uiviewcontroller-keyboard-unrecognized-selector-sent-to-instance-0x7b731ac0?noredirect=1&amp;lq=1" rel="noreferrer noopener nofollow">here</a> . </p>

<p>另请阅读 Apple 关于 <a href="https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIInputViewController_Class/" rel="noreferrer noopener nofollow">UIInputViewController</a> 的文档.</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 应用程序在 ios 中触摸 UITextField 时崩溃,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/39078134/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/39078134/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 应用程序在 ios 中触摸 UITextField 时崩溃