ios - Text in search bar disappears when search button on keyboard is clicked in iPhone -


after typing text in search bar of iphone, when search button clicked on keyboard, text disappears. i've added <uisearchdisplaydelegate, uisearchbardelegate> , bool issearching;

- (void)searchbartextdidbeginediting:(uisearchbar *)searchbar {     issearching = yes; }  - (void)searchbar:(uisearchbar *)searchbar textdidchange:(nsstring *)searchtext {      nslog(@"text change - %d",issearching);      nsstring *str = searchbar.text;      self.searchdisplaycontroller.searchbar.text = str;      //remove objects first.      [filteredarray removeallobjects];       if([searchtext length] != 0) {          issearching = yes;          [self searchtablelist];      }      else {          issearching = no;      }      [self.tableview1 reloaddata]; }  - (void)searchbarcancelbuttonclicked:(uisearchbar *)searchbar {   nslog(@"cancel clicked"); }  - (void)searchbarsearchbuttonclicked:(uisearchbar *)searchbar {    [self searchtablelist];    [searchbar resignfirstresponder]; } - (void)searchtablelist {     searchstring = searchbar.text;      (nsstring *tempstr in tabledata) {         nscomparisonresult result = [tempstr compare:searchstring options:   (nscaseinsensitivesearch|nsdiacriticinsensitivesearch) range:nsmakerange(0, [searchstring length])];         if (result == nsorderedsame) {             [filteredarray addobject:tempstr];         }     } } 

i had same issue uisearchcontroller.
prevented search controller clearing text storing in string , later, after deactivating controller, assigning stored text search bar.

objective c:

-(void) searchbarsearchbuttonclicked:(uisearchbar *)searchbar {     nsstring *text = searchbar.text;     [self.searchcontroller setactive:no animated:yes];     self.searchcontroller.searchbar.text = text; } 

swift 2.x:

func searchbarsearchbuttonclicked(searchbar: uisearchbar) {     let text = searchbar.text     searchcontroller.active = false     searchcontroller.searchbar.text = text } 

hope helps.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -