In an app that's supposed to run on iOS 6 and iOS 7, the cancel button of the search bar embedded in the navigation bar is not shown anymore if the app is run on iOS 7. On iOS 6, it works.
The search bar is in the title view of the navigation bar and the cancel button should be shown if the search bar becomes the first responder:
iOS 7
iOS 6
In an isolated test case, the code is very simple:
@interface MyViewController : UITableViewController<UISearchBarDelegate>
@property (nonatomic) IBOutlet UISearchBar* searchBar;
@end
@implementation MyViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationItem.titleView = self.searchBar;
}
- (void) searchBarTextDidBeginEditing: (UISearchBar*) searchBar {
[searchBar setShowsCancelButton: YES animated: YES];
}
@end
Is this a deliberate change in iOS 7 that I missed in the documentation? If yes, what is supposed to be the alternative?
If not, have I made a mistake in my code?
searchBarTextDidBeginEditing:
is called as expected. It wouldn't work on iOS 6 otherwise. – Codo