My app has a tableview controller that is presented as a form sheet.
On top portion of tableviewcontoller there is a UView and inside of that UIView there is a navigation bar and a searchbar.
Everything works fine older version of IOS but in IOS7 when user taps searchbar everything is messes up.
Normal:
When User starts to type:
After seach ends:
in.h
UITableViewController<UITextFieldDelegate,UISearchDisplayDelegate,UISearchBarDelegate>
@property (nonatomic,weak) IBOutlet UINavigationBar *topBar;
Tried few things but code doesnt seem to be changing anything, when put a breakpoint it enters to delegate methods though
in.m
//-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
// if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
// CGRect statusBarFrame = self.topBar.frame;
// [UIView animateWithDuration:0.25 animations:^{
// for (UIView *subview in self.tableView.subviews)
// subview.transform = CGAffineTransformMakeTranslation(0, statusBarFrame.size.height+50);
// }];
// }
//}
//
//-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
// if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
// [UIView animateWithDuration:0.25 animations:^{
// for (UIView *subview in self.tableView.subviews)
// subview.transform = CGAffineTransformIdentity;
// }];
// }
//}
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect frame = self.searchDisplayController.searchBar.frame;
frame.origin.y += self.topBar.frame.size.height;
self.searchDisplayController.searchBar.frame = frame;
}
}
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
CGRect statusBarFrame = self.topBar.frame;
CGRect frame = self.searchDisplayController.searchBar.frame;
frame.origin.y -= statusBarFrame.size.height;
self.searchDisplayController.searchBar.frame= frame;
}
}
#Additional Info
- (void)viewDidLoad
{
[super viewDidLoad];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
{
//self.searchDisplayController.searchBar.searchBarStyle= UISearchBarStyleProminent;
self.edgesForExtendedLayout = UIRectEdgeNone;
//self.edgesForExtendedLayout = UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight;
}
}
According to break points frame position and sizes are correct but they dont change self.searchDisplayController.searchBar.frame at all
I have also tried
-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[self.topBar setHidden:YES];
}
}
-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[self.searchDisplayController.searchBar removeFromSuperview];
CGRect frame = self.searchDisplayController.searchBar.frame;
frame.origin.y += self.topBar.frame.size.height;
self.searchDisplayController.searchBar.frame = frame;
[self.topView addSubview:self.searchDisplayController.searchBar];
[self.topView bringSubviewToFront:self.topBar];
[self.topBar setHidden:NO];
}
}
How can I solve this issue ?
try setting this value in your table view controller:
if ([self respondsToSelector:@selector(edgesForExtendedLayout)]){
self.edgesForExtendedLayout = UIRectEdgeNone;
}
And change you view hierarchy to have a view, and tableView, search bar and nag bar as it's subviews. Make your table view controller a view controller and make it as the data source and delegate.
Or don't use a searchBarDisplayController and just use a search bar with it's delegate methods:
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
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