UISearchDisplayController's searchResultsTableView's ContentSize is incorrect. Bug in iOS 7?
I had this exact problem. The solution posted on the developer forums here worked for me. Not sure if it's a bug in iOS 7 or just that they changed the way they're doing things but this is the only solution that I found solved my problem.
Solution from the forum post for the lazy:
- (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
}
- (void) keyboardWillHide {
UITableView *tableView = [[self searchDisplayController] searchResultsTableView];
[tableView setContentInset:UIEdgeInsetsZero];
[tableView setScrollIndicatorInsets:UIEdgeInsetsZero];
}
UISearchDisplayController tableview content offset is incorrect after keyboard hide
I solved this by adding a NSNotificationCenter
listener
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView {
//this is to handle strange tableview scroll offsets when scrolling the search results
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardDidHide:)
name:UIKeyboardDidHideNotification
object:nil];
}
Dont forget to remove the listener
- (void)searchDisplayController:(UISearchDisplayController *)controller willHideSearchResultsTableView:(UITableView *)tableView {
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIKeyboardDidHideNotification
object:nil];
}
Adjust the tableview contentsize in the notification method
- (void)keyboardDidHide:(NSNotification *)notification {
if (!self.searchDisplayController.active) {
return;
}
NSDictionary *info = [notification userInfo];
NSValue *avalue = [info objectForKey:UIKeyboardFrameEndUserInfoKey];
CGSize KeyboardSize = [avalue CGRectValue].size;
CGFloat _keyboardHeight;
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIDeviceOrientationIsLandscape(orientation)) {
_keyboardHeight = KeyboardSize.width;
}
else {
_keyboardHeight = KeyboardSize.height;
}
UITableView *tv = self.searchDisplayController.searchResultsTableView;
CGSize s = tv.contentSize;
s.height -= _keyboardHeight;
tv.contentSize = s;
}
UISearchDisplayController Frame Issue
If anyone is interested, @enreas pointed out towards the right direction: https://stackoverflow.com/a/19162257/968925
IOS 7 table view content size issue
As you mentioned in the comment, you have a custom cell, maybe with custom layout and view hierarchy. Be sure to add views to the cell's contentView
instead the cell, that is changed in iOS7.
Strange UISearchDisplayController view offset behavior in iOS 7 when embedded in navigation bar
I remember running into the same exact problem that you are observing.There could be a couple of solutions you can try.
If you are using storyboards
You should click on the view controller or TableView Controller which you have set up for your tableview and go to its attribute inspector and look under ViewController section and set the Extend Edges section to be under Top Bars.If you are not using storyboards you can manually set the settings using the viewcontrollers edgesForExtendedLayout property and that should do the trick. I was using storyboards.
Search Display Controller result tableview cannot scroll in iOS 6
Turns out this is a (not well) known issue of UISearchController
's table view in iOS 6. My temporary solution is to get the contentSize
from willShowSearchResultsTableView
and programmatically set it to the table view in viewDidLayoutSubviews
:
- (void) viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
if ([self.searchController isActive]){
// fix wrong content size due to search bar glitch in iOS 6
self.searchController.searchResultsTableView.contentSize = newContentSize;
}
}
Hope this helps anyone who encounters the same problem as mine.
iOS7 - Storyboards for 6.1 and 7.0 look misaligned
Many of the defaults for interface items have changed for iOS 7. The standard default button is just a piece of text, with no borders. Also, the screen displays underneath the nav bar now. Use the edgesForExtendedLayout setting and change it from its default of UIRectEdgeAll to get the view to not show under other things.
Welcome to iOS 7! Its not a bug-- its the new default interface.
Check out the iOS 7 transition guide here.
Here is where to set it in Interface Builder:
Related Topics
Nsstring Encoding Returns Nil on Url Content
Modify Pull to Refresh in Swift
How to Round the Corners of a Button
How to Change the Image Displayed in a Uiimageview Programmatically
How to Convert Nsinteger to Nsstring Datatype
Uiwindow Not Showing Over Content in iOS 13
Alternative Ways to Push View Controllers with Storyboard Programmatically
Create a Button Programmatically and Set a Background Image
App Crashes Only on Testflight Build
iOS Extensions with Multiple Targets
Detect Shake Gesture iOS Swift
Decompilation Possibilities in iOS and How to Prevent Them
Understanding Uilocalnotification Timezone
Uiview.Animatewithduration Swift Loop Animation
Retrieve User Defaults Information from an Apple Watch
Detected a Case Where Constraints Ambiguously Suggest a Height of Zero