I'm updating my app for iOS 7 and one of my functions that allowed a search bar search button to be activated with no text in the search bar stopped working. I used the following code. ANy suggestions on how to make it work again? Thanks in advance.
UITextField *searchBarTextField = nil;
for (UIView *subview in self.searchBar.subviews)
{
if ([subview isKindOfClass:[UITextField class]])
{
searchBarTextField = (UITextField *)subview;
break;
}
}
searchBarTextField.enablesReturnKeyAutomatically = NO;
In iOS 7 there is a small change, now you have to iterate two levels.
for (UIView *subView in self.searchBar.subviews){
for (UIView *secondLeveSubView in subView.subviews){
if ([secondLeveSubView isKindOfClass:[UITextField class]])
{
searchBarTextField = (UITextField *)2ndLeveSubView;
break;
}
}
}
There is directly the option enablesReturnKeyAutomatically on search bar.
searchbar.enablesReturnKeyAutomatically = NO;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With