菜鸟教程小白 发表于 2022-12-11 20:54:43

ios - UISearchBar 不应关闭导航 Controller


                                            <p><p>我正在构建一个 iOS 应用程序,通过从另一个 ViewController 执行以下转换,我得到一个带有 <code>UISearchController</code> 的 <code>UITableViewController</code>: </p>

<pre><code>let search = UITableViewController()
let nav = UINavigationController(rootViewController: search)
self.present(nav, animated:true, completion:nil)
</code></pre>

<p>但是,当我按下 中的“取消”按钮时,应用程序会弹出整个导航 Controller 并返回查看 !我如何让它只是取消搜索而不是弹出整个导航 Controller ?我觉得这应该是默认行为,我错过了一些东西。 </p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我不明白你为什么感到惊讶。你说 <code>present</code> 来创建一个由导航 Controller 和表格组成的模式(呈现) ViewController :</p>

<pre><code>let nav = UINavigationController(rootViewController: search)
self.present(nav, animated:true, completion:nil)
</code></pre>

<p><code>present</code> 是 <code>nav</code>,即导航 Controller 。那么它的反面是什么?它是 <code>dismiss</code>,你的 <code>dismiss</code> 是 <code>nav</code>。所以我会<em>期望</em>导航 Controller 最终消失。</p>

<p>这里真正的问题可能是你所做的根本不是你如何使用 UISearchController。搜索 Controller <em>本身</em>是一个 ViewController ,<em>它</em>应该显示结果 TableView 。您只是没有正确处理它以使其做到这一点。您没有显示任何有关您的搜索 Controller 及其配置的信息,因此无法提供更多细节。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - UISearchBar 不应关闭导航 Controller ,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/53584082/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/53584082/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - UISearchBar 不应关闭导航 Controller