0
votes

I am showing some Lists in UITableView. For sorting purpose i have used UISearchBar. I am getting some strange behaviors of Cancel button

Steps to reproduce

  1. Search for something
  2. Notice that while you are searching, there is a 'Cancel' button that will get rid of the onscreen keyboard.
  3. Now tap into detail of one of the search results
  4. Then go back
  5. The search results are still there, and the search bar is there, but the 'Cancel' button is missing.
  6. So there is no way to remove the onscreen keyboard without closing the application and re-opening.

But these scenario occurring only in iphone not in simulator. I am able to see Cancel button when i go back to first screen.

I have used these delegates:

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{   
  searchBar.text = nil; 
  [searchBar resignFirstResponder];
  isSearch = NO;
}

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar
{  
  searchBar.showsScopeBar = NO;  
  [searchBar sizeToFit];  
  [searchBar setShowsCancelButton:NO animated:YES]; 
  return YES;   
}  

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{  
  searchBar.showsScopeBar = YES;  
  [searchBar sizeToFit];  
  [searchBar setShowsCancelButton:YES animated:YES];  
  isSearch = YES;
  return YES;    
}  

Please help

1

1 Answers

1
votes

Try this post.

I would suggest you use UISearchDisplayController - a helpful tutorial?