Forum Xamarin.iOS

Bug with UISearchController with null search results controller

GerryHighGerryHigh USBeta ✭✭✭

This appears to be a bug in that if you create UISearchController with a null search results controller the SearchBar is always null.


        var searchController = new UISearchController(); 

var searchController = new UISearchController() {
WeakDelegate = this,
DimsBackgroundDuringPresentation = false,
WeakSearchResultsUpdater = this

searchController.SearchBar will always be null, regardless of where in the view lifecycle you try to access it.

A swift version that works:

Has anyone successfully used UISearchController with a null results view controller (e.g. I want to display the search results in the same view controller that displays my searchable content).

  • Gerry


  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    As a workaround, does passing this to the constructor work (assuming this is a UIViewController)?

  • GerryHighGerryHigh USBeta ✭✭✭

    I have previously tried that but I got a runtime crash due to it complaining about presenting a view controller on top of itself (when you enter into the search fields). So it was a no-go for me.

  • GerryHighGerryHigh USBeta ✭✭✭

    FYI Kinda hackish (IMO) but this is what was resolved by @RolfBjarneKvinge as a solution:

    If I create the UISearchController like this it works:

    var searchController = new UISearchController((UIViewController) null);
    Console.WriteLine ("SearchController.SearchBar is: {0}", searchController.SearchBar == null ? "null" : "not null");


    SearchController.SearchBar is: not null

  • DaveHuntDaveHunt USMember ✭✭✭✭✭

    I guess it makes a kind of perverted sense. The docs say to pass null to get the desired result. Passing nothing isn't the same as passing null. Lame, I know, but it does explain it.

  • rayyadrayyad CAMember ✭✭

    Hey All,
    I'm having this issue right now. The example Xamarin provides shows them using another ViewController...I don't want that. I want to use my current tableviewcontroller. How do I pass nill into the constructor!?

  • SipkeSchoorstraSipkeSchoorstra NLMember ✭✭

    It sure helped me. Thanks!


    After searching for an hour, this helped me!

Sign In or Register to comment.