簡體   English   中英

無法停止搜索欄顯示取消按鈕

[英]Cannot stop search bar from showing cancel button

因此,當我單擊搜索欄時,我試圖阻止取消按鈕的出現。 我已經試過了-

[self.searchDisplayController.searchBar setShowsCancelButton: NO animated:NO];
NSLog(@"CANCEL BUTTON : %hhd", self.searchDisplayController.searchBar.showsCancelButton);

日志告訴我showsCancelButton的值為0 ,表明它已關閉。

發生什么了?

您只需在“ searchDisplayControllerWillBeginSearch”委托方法中將取消按鈕設置為隱藏即可,例如:

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller{
    controller.searchBar.showsCancelButton = NO;
}

如果您不使用UISearchDisplayController,也可以在下面使用

-(void) searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    //This'll Show The cancelButton with Animation
    [searchBar setShowsCancelButton:NO animated:YES];
}

嘗試這個,

    - (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
        searchBar.showsCancelButton = NO;
        return YES;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM