ios - 如何让 UISearchController 与 UISearchBar Interface Builder 控件一起使用?
<p><p><strong>列表项</strong></p>
<p>如何让 UISearchController 与 Interface Builder 中的搜索栏控件一起使用?我试过以下代码:</p>
<pre><code>@IBOutlet weak var searchBar: UISearchBar!
searchController.searchBar = searchBar
</code></pre>
<p>这在编码时给了我一个错误,说 searchController.searchBar 是一个 get-only 属性。</p>
<pre><code>@IBOutlet weak var searchBar: UISearchBar!
searchBar = searchController.searchBar
</code></pre>
<p>这给了我想要的 UI,但搜索不起作用。</p>
<pre><code>var searchBar: UISearchBar!
searchBar = searchController.searchBar
NSLayoutConstraint(searchBar, ..... )
</code></pre>
<p>这可行,只是当我开始在搜索栏中输入时,搜索栏消失了。**</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>UISearchController 的 searchBar 是一个计算属性,因此您必须存储自定义的 searchBar 并在调用 searchBar 时返回它。</p>
<pre><code>var yourSearchBar = yourSearchBar()
override var searchBar: UISearchBar {
get{
return yourSearchBar;
}
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - 如何让 UISearchController 与 UISearchBar Interface Builder 控件一起使用?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/47987566/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/47987566/
</a>
</p>
页:
[1]