iOS 9 searchBar disappears from table header view when UISearchController is active

后端 未结 13 1281
無奈伤痛
無奈伤痛 2020-12-07 20:37

The structure:

View1 (click a button) -> present modally (MyModalView: UITableViewController)

MyModalView has UISearchController embedded. The searchBar of U

相关标签:
13条回答
  • 2020-12-07 21:16

    Thanks @wiles duan and @Techprimate

    In my case, I fixed this issue by setting:

    self.definesPresentationContext = NO;
    

    And implement the following 2 methods in UISearchControllerDelegate

    - (void)willPresentSearchController:(UISearchController *)searchController {
        // do something before the search controller is presented
        self.navigationController.navigationBar.translucent = YES;
    }
    
    -(void)willDismissSearchController:(UISearchController *)searchController
    {
        self.navigationController.navigationBar.translucent = NO;
    }
    
    0 讨论(0)
  • 2020-12-07 21:19

    It works

    override func viewDidLoad() {
        super.viewDidLoad()
    
        self.extendedLayoutIncludesOpaqueBars = !self.navigationController!.navigationBar.translucent
    }
    
    0 讨论(0)
  • 2020-12-07 21:19
    sc.hidesNavigationBarDuringPresentation = false
    

    does the trick for me

    lazy var searchController:UISearchController = {
            let sc = UISearchController(searchResultsController: nil)
            sc.searchResultsUpdater = self
            sc.obscuresBackgroundDuringPresentation = false
            sc.searchBar.placeholder = "Search"
            sc.hidesNavigationBarDuringPresentation = false
            return sc
        }()
    
    0 讨论(0)
  • 2020-12-07 21:25

    None of them worked for me, I fixed it using this hack

    func position(for bar: UIBarPositioning) -> UIBarPosition {
        if UIDevice.current.userInterfaceIdiom == .pad {
            return .top
        } else {
            if iOSVersion <= 9 {
                return .top
            }
            return .topAttached
        }
    
    
    }
    
    0 讨论(0)
  • 2020-12-07 21:26

    It seems all of us got the same problem but they were solved in different ways. However none of the suggested answers worked for me :(. Nevertheless thank you all for your time.

    I got a solution that solved my problem. It is setting Extend Edges - Under Opaque Bars of my (MyModalView: UITableViewController) to true in the Storyboard using Interface Builder.

    In summary:

    MyModalView: UITableViewController, in Storyboard using Interface Builder has

    Extend Edges: - Under Top Bars ticked - Under Bottom Bars ticked - Under Opaque Bars ticked

    0 讨论(0)
  • 2020-12-07 21:29

    If you want to hide you navigation bar, and present search controller full screen, set the following on your navigation bar and search bar won't dissapper:

    navigationController?.navigationBar.translucent = true
    
    0 讨论(0)
提交回复
热议问题