1

I am calling the following function to successfully hide my search bar in viewDidLoad:

- (void)hideSearchBar {
    CGRect newBounds = self.tableView.bounds;
    newBounds.origin.y = newBounds.origin.y + _searchBar.bounds.size.height;
    self.tableView.bounds = newBounds;
}

enter image description here

but if I call the exact same function in (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar the top row of my table view becomes overlapped with the navigation bar. Why is this overlap only happening when calling the hide function from searchBarTextDidEndEditing?

enter image description here

Adam Johns
  • 35,397
  • 25
  • 123
  • 176
  • I wonder whether the `viewDidLoad` one is wrong. `viewDidLoad` is too early to know what `self.tableView.bounds` is; the table view has not yet been put into the interface. – matt Mar 28 '14 at 04:10
  • I think that would be true for height, but origin I think is fine. I got the code from [this](http://www.raywenderlich.com/16873/how-to-add-search-into-a-table-view) tutorial. Usually a reputable site. – Adam Johns Mar 28 '14 at 04:15
  • I guess my question is: if you pull the call out of `viewDidLoad` and put it in `viewWillAppear:`, does it still work? If so then we have something to sink our teeth into... – matt Mar 28 '14 at 04:21
  • putting the call in viewwillappear resulted in the same thing as having it in viewdidload - it still worked fine. However I noticed that If I make the nav bar translucent it works fine…must be some weird ios bug – Adam Johns Mar 28 '14 at 04:26
  • Okay, so let's go back to the problem with `searchBarTextDidEndEditing:`. What happens if you wrap the call to `hideSearchBar` in some delayed performance? – matt Mar 28 '14 at 04:29

1 Answers1

1

An answer from this question helped me realize this is somehow related to the nav bar being translucent. When I set the nav bar translucent to NO I had the issue. When I stopped making it NO, it works fine.

Community
  • 1
  • 1
Adam Johns
  • 35,397
  • 25
  • 123
  • 176
  • Okay but it would be nice to _solve_ it. Let's try my delayed performance idea before you go knuckling under and changing your translucency. After all if the translucency is causing underlapping here, why doesn't it cause underlapping in the first place? – matt Mar 28 '14 at 04:31
  • I'll try to investigate more tomorrow and try out the delay – Adam Johns Mar 28 '14 at 04:32