2016-04-26 13 views
0

我在NavigationBar中添加SearchBar視圖。如何在SearchBar中單擊取消按鈕時,它不是焦點

[self.navigationController.view addSubview:self.searchBar]; 

當我搜索...

enter image description here

搜索完成後...

enter image description here

如果我想取消(刪除)搜索欄,我必須點擊取消按鈕兩次刪除SearchBar。 (一次搜索焦點搜索欄,一次點擊取消)。

如何在SearchBar中單擊一次即可取消像(x)按鈕(清除文本按鈕)? 或者SearchBar如何關注? (在這條路上我可以點擊取消關閉搜索欄只有一個水龍頭)

+0

你想隱藏取消按鈕時點擊取消? – 2016-04-26 06:12:30

+0

我想關閉(移除)一次點擊取消按鈕的SearchBar。 – Plagorn

回答

0

實現搜索欄的委託方法:

- (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar { 
     self.navigationController.navigationBarHidden = NO; 
     [mySearchBar setAlpha:0.0]; 
    } 

希望你有做這個的想法。如果你想&然後單獨顯示/隱藏searchBar,你也可以直接將它添加到導航控制器本身。

+0

試試這個會幫助你 – 2016-04-26 06:45:58

0
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller 
{ 
    controller.active = YES; 

    [self.view addSubview:controller.searchBar]; 
    [self.view bringSubviewToFront:controller.searchBar]; 
} 

- (void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView { 

    tableView.frame = self.archiveListTblView.frame; 
} 

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller 
{ 
    controller.active=NO; 

    [self.view addSubview:controller.searchBar]; 
} 
1

搜索

刪除此行後不要放棄你的鍵盤[搜索欄resignFirstResponder]

它將工作

enter image description here

相關問題