This is the hierarchy of the controls
This is when i tap on searchbar textfield (everything is normal here)
But when i type, this is how the results are displayed. there is a gap between searchbar and table header where cells are visible.
And also, when i rotate while searching this happens to searchbar. Though xcode isn't allowing adding constraints from the autolayout menu on bottom.
Related
I have several different tableviewcontrollers connected to tabs. All were created in storyboard.
For all but one, I don't have a search bar. For one, however, I do have a search bar. When you view the one with the searchbar the table view does not take up the whole space at the bottom. At the top it shows the search bar as you would expect. But at the bottom, it leaves empty space.
In the measurement inspector for the storyboard, the view controller appears to have the same dimensions 600x600 as the tableview for the other view controllers.
Some answers suggest that the table row height may differ with the search bar controller but I tried changing that and it did not have any effect.
Can anyone suggest what might be causing this problem?
I have an iOS8 app which has a UITabBarViewController as part of its master view. Embedded within that is a UITableViewController which has some UITextFields embedded in some of the cells.
When a text view is tapped, the keyboard automatically appears. If necessary, the 'view' is adjusted to allow the textView to remain showing so data can be entered.
The problem is that the tabBarController and associated tabs are also moved up. This is usually OK unless my phone is in landscape which leaves very little room to show the tableview and allow effective gestures (e.g. swiping the tableview up/down).
So, is there a way to get the keyboard to only push-up the tableview within the tabBarController, rather than the whole outer frame also being moved up? Picture below shows the problem. The device is in landscape
I looked in this thread and tried everything I saw, and I can't seem to get it working.
Scroll to top of UITableView by tapping status bar
I have a UINavigationController and a UITabBarController. The application first opens to a UICollectionView.
When the user makes a selection, it brings up a ScrollView run by a custom UIViewController ("ScrollViewController"). The ScrollViewController makes four TableViewControllers and puts their TableViews in the ScrollView side by side with paging enabled, and has a floating UIPageControl as well.
Tapping the top bar scrolls the CollectionView to the top, but once I bring up the ScrollView, I can't scroll up from anywhere. I have tried setting all the TableViews' scrollsToTop to NO, no change.
Any suggestions?
That's correct. You can only have one scroll view controlled by the tap of the status bar. If you have multiple scroll views on the screen (either hidden or visible) you can set one of them to be controlled by the status bar tap by disabling the auto scroll on all of the other scroll views using scrollsToTop = NO, that includes anything that uses a scroll view within it, like a table view or a pager.
self.myTableView.scrollsToTop = NO;
According to Apple's documentation:
On iPhone, the scroll-to-top gesture has no effect if there is more than one scroll view on-screen that has scrollsToTop set to YES.
I have a UITableView which has a UISearchBar subview. This is all on the view of a UIViewController along with a few other subviews (labels, text fields and such).
The search bar and content offset of the table are acting quite strangely, but it seems dependent on the order in which these views are added to the main view in the xib. I created a sample project with just my table/search and a label in order to test, and the result is the same. When the table is added after the label, everything works fine:
Setup:
Correct and Expected Result:
However, if I simply change the order in which my 2 subviews sit on the main view (aka table added before the label) then weird things start happening.
Apparently bad setup:
Weird offset of Search Bar:
I'm not changing anything else whatsoever, so why does Xcode seem to care which order these subviews are added to the main view?? If I scroll up on the "bad" table setup, the search bar disappears immediately at its top edge, but the table's content will continue to scroll up until it reaches the top of the frame that was set in the xib. Scroll back down and the search bar doesn't reappear until the strange lowered location. This is in Xcode 5.1.1, not the new beta. The result is the same with or without Autolayout turned on.
Any idea why this is happening? Is this a bug, or am I missing something? (I didn't post any code because all I'm doing is setting the number of sections, rows, and setting the text on the cell. Not messing with content insets, offset, anything. I load the view from the app delegate as the root of a nav controller)
This happens because a UIViewController's property called automaticallyAdjustsScrollViewInsets
With iOS 7, UIViewControllers have a property called
automaticallyAdjustsScrollViewInsets, and it defaults to YES. If you
have a scroll view that is either the root view of your view
controller (such as with a UITableViewController) or the subview at
index 0, then that property will adjust both the contentInset and the
scrollIndicatorInsets. This will allow your scroll view to start its
content and scroll indicators below the navigation bar (if your view
controller is in a navigation controller).
From Big Nerd Ranch
If you are using storyboards, you can change it by selecting the view controller and in the attributes inspector deselect Adjust scroll view insets.
Here is its description from apple documentation:
Default value is YES, which allows the view controller to adjust its
scroll view insets in response to the screen areas consumed by the
status bar, navigation bar, and toolbar or tab bar. Set to NO if you
want to manage scroll view inset adjustments yourself, such as when
there is more than one scroll view in the view hierarchy.
I have same problem before about position of tableview and searchbar. i tried the following and it works for me.
If you do not write code for that and if it is only problem of xib or storyboard then try all outlet's autosizing and origin setting to fix its position and see the difference. it may be work for you.
Update : automaticallyAdjustsScrollViewInsets has been deprecated in ios 11 and a new field contentInsetAdjustmentBehavior has been introduced.
if #available(iOS 11.0, *) {
tableview.contentInsetAdjustmentBehavior = .never
} else {
automaticallyAdjustsScrollViewInsets = false
}
UITableView header can contains only one UIView, so if you need UISearchBar plus UILabel, you need to wrap they into UIView and add this view as UITableView header.
I have a UISearchBar and a UITableView positioned inside the view of a UIViewController. The table itself and the search function are working fine, but there is a problem with how the search results are layered over the top of the search bar. I'm sure there is something I have misconfigured, but being new to iOS development, I cannot figure out exactly what it is.
This is how the UISearchBar and UITableView are currently positioned within the view:
However, when your tap the search bar, the transparent overlay which appears covers it up. I would expect it to only appear below the search bar or perhaps for the search bar to move up?
If you begin to type, the search results appear, but the search bar itself has now been completed covered up:
I have tried the following:
Moving the UISearchBar to the header of the UITableView. The result of this is that, when searching, the search bar is moved to the very top of the view but when the search has finished, it then is positioned way off the the left so only the very right edge of the search bar is visible!
Disabling the Under Top Bars and Under Bottom Bars options under the Extended Edges options for the view controller (options in Xcode Interface Builder). This results in the same problem, except the Tab Bar and Nav Bar are a different colour (see image below, with keyboard hidden):
This view has been built using a Storyboard. Here is the heirarchy for reference (the Scroll View is hidden in all the screenshots as it only appears on the right once a search result has been tapped):