0
我更新我的應用程序來處理導航欄下的搜索欄的新的iOS 11搜索行爲:如何辭退的ViewController而navigationItem的搜索欄具有焦點
- (void)viewDidLoad
{
[super viewDidLoad];
UISearchController *searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
self.navigationItem.searchController = searchController;
// Those are optional, but that's what I want my UI to look like
searchController.hidesNavigationBarDuringPresentation = NO;
searchController.obscuresBackgroundDuringPresentation = NO;
self.navigationItem.hidesSearchBarWhenScrolling = NO;
}
我也有我的看法按鈕,該抽頭時將關閉當前視圖控制器:
- (IBAction)dismiss:(id)sender
{
[self dismissViewControllerAnimated:YES completion:nil];
}
的問題是:(即是第一應答器),如果searchController的搜索欄具有焦點當用戶點擊該按鈕時,視圖控制器沒有被駁回。
- 在按鈕上的第一抽頭,搜索欄失去其焦點和鍵盤隱藏(彷彿
[searchBar resignFirstResponder]
已稱); - 在第二次點擊時,視圖控制器最終被解散。
我怎樣才能使按鈕上的第一次輕觸立即關閉該視圖控制器(移除搜索欄的焦點的副作用)?