How do you dismiss a UISearchController ? (iOS 8 and follow)

前端 未结 5 564
野性不改
野性不改 2020-12-25 10:53

This must be trivial, but I can\'t find how you\'re supposed to dismiss a UISearchController programmatically?

Note that it\'s the new UISearchController (introduced

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-25 11:14

    OK so after more testing, turns out you just have to set:

    searchController.active = false
    // or swift 4+
    searchController.isActive = false
    

    This is the first thing I tried but I called it in one of the UISearchControllerDelegate methods which didn't work (probably should have called it with dispatch_async (halbano's answer seems to confirm that)).

    Anyway, since I couldn't find that answer online, I'm answering my own question, I hope that it'll help someone.

提交回复
热议问题