2015-01-09 50 views
3

我想使用UISearchController为我的iPhone应用程序显示一个简单的搜索屏幕。 我用的UITableViewControllerUISearchController我内嵌在的UINavigationControllerIOS8 UISearchController直接显示搜索栏

  • 这让我下面的屏幕(状态1

searchcontroller with navigation bar

  • 当用户点击搜索字段时,我会看到下面的屏幕(状态2): 搜索栏很好地显示在状态栏下方的屏幕顶部。

searchcontroller activated

我想要做的是让状态2马上而不去状态1

我尝试添加该代码

presentViewController(searchController, animated: true, completion: nil) 

但它或者不显示搜索栏,如果动画是假的,或者显示为我想要但是在不必要的tra之后nsition是temporaryly显示导航栏

+0

你问题让没有意义。 _You_是将搜索字段作为表视图的标题视图以(状态1)开始的那个人。如果那不是你想要的,你为什么这样做?如果您希望搜索字段存在于导航栏中,为什么不把它放在导航栏中呢? – matt 2015-01-09 19:20:54

回答

6

好,我刚刚找到如何做到这一点阅读这个答案UISearchController in a UIViewController

我只需要添加搜索栏这样来获得预期的效果

searchController.hidesNavigationBarDuringPresentation = false 
    // tableView.tableHeaderView = searchController.searchBar 
    navigationItem.titleView = searchController.searchBar 
+0

你可能想接受你自己的答案 – Besi 2015-06-12 13:13:58

相关问题