我可以将 UISearchController 与故事板一起使用吗? [英] Can I use a UISearchController with a storyboard?

查看:45
本文介绍了我可以将 UISearchController 与故事板一起使用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以让我使用 UISearchController 来制作 UISearchBar 的故事板?我有一个带有导航栏的故事板 UI,其中包含我的搜索栏.如果我能保持这种方式就好了,因为以编程方式设置布局真的很不方便.我知道旧的 UISearchDisplayController 可以制作故事板.有没有办法用 UISearchController 做类似的事情?

Is there a way to use UISearchController in a way that lets me storyboard the UISearchBar? I have a storyboarded UI with a navigation bar which contains my search bar. It would be great if I could keep it this way because setting up the layout programmatically would be really inconvenient. I know the old UISearchDisplayController could be storyboarded. Is there a way to do something similar with UISearchController?

推荐答案

UIView 添加到您的布局.这将是您的 UISearchBar 的容器.然后以编程方式实例化 UISearchController,然后将搜索栏添加到容器中:

Add a UIView to your layout. That will be the container for your UISearchBar. Then programmatically instantiate the UISearchController and then add the searchbar to the container:

let searchController = UISearchController(searchResultsController: searchResultsController)
searchBarContainer.addSubview(searchController.searchBar)

这篇关于我可以将 UISearchController 与故事板一起使用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆