how to show cancel button of searchbar?

后端 未结 6 1372
深忆病人
深忆病人 2021-02-19 06:11

I want to hide the Navigation Bar of my page when the user start editing on the searchbar, I also want to show a cancel button.
It is done but my cancel button is not access

6条回答
  •  执念已碎
    2021-02-19 06:41

    Use this code to show/Hide the cancel Button in SearchBar

    As user will start the Editing in SearchBar SHow the Cancel Button.

    Below methods will only be accessible if you have set the delegate of SearchBar properly.

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

    Hide The CancelButton as User Click on Cancel Button

     - (void)searchBarCancelButtonClicked:(UISearchBar *) searchBar
     {
            //This'll Hide The cancelButton with Animation  
          [searchBar setShowsCancelButton:NO animated:YES];
           //remaining Code'll go here
     }
    

提交回复
热议问题