Reputation: 50
I have a UISearchBar programatically and works but if I try to set a placeholder and user tap to search something my app crash. This is my code:
Property
@property (strong, nonatomic) UISearchBar *mySearchBar;
Implementation
self.mySearchBar = [[UISearchBar alloc] init];
self.mySearchBar.delegate = self;
self.mySearchBar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
self.mySearchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.mySearchBar.translucent = NO;
self.mySearchBar.returnKeyType = UIReturnKeySearch;
self.mySearchBar.autocorrectionType = UITextAutocorrectionTypeNo;
self.mySearchBar.inputAccessoryView = toolBarKeyboard;
self.mySearchBar.placeholder = @"Artist, Team or City";
This line makes crash when user tap in uisearchbar to find some data
self.mySearchBar.placeholder = @"Artist, Team or City";
Someone else with this error?
I use:
Upvotes: 0
Views: 482
Reputation: 922
I know this is an old question, but if someone else is facing this issue, this can solve the problem:
UITextField* tfSearchBar = [self.mySearchBar valueForKey:@"_searchField"];
tfSearchBar.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"Artist, Team or City"];
Hope it helps
Upvotes: 2