7

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: enter image description here

When User starts to type: enter image description here

After seach ends: enter image description here

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;
    }
}

enter image description here

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 ?

SpaceDust__
  • 4,844
  • 4
  • 43
  • 82

2 Answers2

2

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
ManicMonkOnMac
  • 1,476
  • 13
  • 21
2

I had a similar problem, I think searchDisplayController expands searchBar size to full tableHeaderView size (I really don't know why it doing this). I had searchbar and one custom toolbar (both 44px height) in tableHeaderView.

I've workarounded it with:

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    self.tableView.tableHeaderView.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 44);
}

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller {
    self.tableView.tableHeaderView.frame = CGRectMake(0, 0, self.tableView.bounds.size.width, 88);
}

So I just setting tableHeaderView to the size of single UISearchBar when entering search and set it back when all animations complete. This solved my problem. Even animations still work (but they does not in the childViewController. No idea why)

ReDetection
  • 3,146
  • 2
  • 23
  • 40