Fixed UISearchBar using UISearchController - Not using header view of UITableView

吃可爱长大的小学妹 提交于 2019-11-28 19:40:53

You can place the UISearchBar of UISearchController in the navigation bar so that it remains fixed

self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;

// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;

self.definesPresentationContext = YES;
anil

Create One uiview and added searchController.searchbar inside this view. After that add this view in your viewController.view. above the table view.

then it will not scroll.

   var viewTemp = UIView(frame: CGRectMake(0.0, 64.0,320.0, 44))
   viewTemp.addSubview(self.searchController.searchBar)
   self.view.addSubview(viewTemp);

Instead of directly keeping UISearchBar on top of UITableView. Put the UISearchBar inside a view.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!