如何激活具有预设术语的UISearchDisplayController?

Tom*_*ift 5 uisearchdisplaycontroller ios

我正在以一种非常规的方式使用UISearchViewController.

我的UISearchBar最初是隐藏的.当用户点击按钮时,我取消隐藏UISearchBar并激活UISearchViewController.我还设置了搜索栏的文本,并告诉搜索栏成为第一响应者.

问题是UISearchDisplayController创建的灰色叠加层仍然可见.除非我预设的文本被清除,并且用户开始重新输入,否则它不会消失.

    self.searchDisplayController.searchBar.hidden = NO;
    self.searchDisplayController.searchBar.text = @"term";
    [self.searchDisplayController.searchBar becomeFirstResponder]; // this actually appears to activate everything
    [self.searchDisplayController setActive: YES animated: YES]; // this activates but does not set the searchbar to 1st responder...
Run Code Online (Sandbox Code Playgroud)

为什么UISearchDisplayController继续显示它的灰色叠加,我该如何清除它?

Tom*_*ift 12

改变呼叫的顺序似乎可以解决问题.不知道为什么.

[self.searchDisplayController setActive: YES animated: YES]; 
 self.searchDisplayController.searchBar.hidden = NO;
self.searchDisplayController.searchBar.text = @"term";
[self.searchDisplayController.searchBar becomeFirstResponder]; 
Run Code Online (Sandbox Code Playgroud)