Search code examples
objective-cuisearchbarxcode11ios13

ios 13 - Custom SearchBar with UISearchBar _searchField not working


Before Xcode-11-Beta (ios13) below code for custom searchbar value for key to get textField working fine. Now getting below crash log.

'NSGenericException', reason: 'Access to UISearchBar's _searchField ivar is prohibited. This is an application bug'

- (UITextField *)textField
{
 return [self valueForKey:@"_searchField"];
}

Any help appreciated.


Solution

  • The SDK now provides UISearchBar.searchTextField so you can simply replace your private API implementation with the public API.

    searchBar.searchTextField.backgroundColor = [UIColor blueColor];