In the video, it's a little difficult to see what's going on, so I'll try to explain it.
https://youtu.be/yOrCJB9yZlg
I have UIViewController with UITableView inside its root view. Binded via Autolayout (there is no difference how it's binded: to SuperView or to SafeArea).
SearchBar added like this:
let search = UISearchController(searchResultsController: nil)
self.navigationItem.searchController = search
When I slowly scroll table, the transition between large navbar and compact navbar, and then animation of showing in and out of searchBar is too fast. Searchbar jumping in/out of navbar instead of smoothly opened/closed; navbar transitioning is jumping between two states, large and compact, without smoothly passes through the middle half-opened state while you slowly moving your finger on screen, like in system apps (Mail, Phone, Messages, Contacts etc).
I made the example from an empty project to demonstrate the issue; there isn't any changes to navigation bar logic, or any logic at all. Just two new VC's and this odd behaviour.
If i create xCode's "Master-Details" project example and add UISearchController to it, it will work properly. I assume its because they used UITableViewController instead of UIViewController + UITableView inside.
What the reason of this behaviour and how to fix it?
I had the same problem with the search controller transition and tableview.
like this its flickering or tableview was jumping. The search controller was on the navigation item.
The key solution is to remove safe area guide from your view controller and assign top bottom left right constraints to your tableview. It will be smooth like this
What you have done is correct. Did you try running your code in a device? Feels more like a glitch in the simulator. I tried what you tried and it works fine for me in the device. Whereas the glitch occurs in simulator.
Refer to this article. They have explained step by step process.
This is a known problem and your code seems fine. This problem was already discussed here.
Problem appears when you're using UIScrollView or its subclasses with large navigation titles. It doesn't work. Problem disappears when you use UICollectionViewController or UITableViewController instead.
I have a class (movieTable.m) with TableView populated with many cells.
As i Clicked one of them, the navigation controller brings in the other scene done in the StoryBoard.
When i get back, still with Navigation Controller, i find the TableView moved little bit down.
As I debugged the Hierarcy i found that UITableViewWrapperView is scrolled down from UITableView.
Edit: The funny thing is: if i put a UiSegmentedControl in the UiView the issue disappears.
Why this? i didn't tell the code to move it. Maybe I'm getting wrong with the timing?
so to making clear the ideas, there's two images:
Hierarchy before/after changing the scene
The Code if you want to see it is in this following GitHub: GitHub
Thank you all for helping&hints.
this worked for me
add
self.automaticallyAdjustsScrollViewInsets = NO;
to your viewDidLoad of the moveiTable.m
I'm trying to figure out, given a UIViewController subclass, how to add a UINavigationBar to it. All the questions and answers seem to be either embed it in a navigation controller (not possible in this case) or via Storyboard, but I need to do it completely in code.
Do I just add it as a subview of the view controller's view? Will it become topLayoutGuide after I pin it to the topLayoutGuide, which would be the status bar prior to adding it? Or am I supposed to be setting an attribute on the view controller I cannot figure out, instead of adding it?
Your on the right track, you just add as a subview like you would any other view. The trick to the status bar is setting yourself as the navigationBar delegate and returning UIBarPositioningTopAttached in the delegate method
.....
self.customNavigationBar.delegate = self;
[self.addSubview self.navigationBar];
....
- (UIBarPosition)positionForBar:(id<UIBarPositioning>)bar {
return UIBarPositioningTopAttached;
}
Description of the problem: with iOS 7 in grouped UITableView there is a gap between the top of the table view and the first cell.
The strange part is that when I load the content for the first time the table appears to be ok (first image), but when I scroll down a space appears between top and first cell (second image):
With style plain this behavior does't occur but unfortunately I need to use the grouped table view style.
Any ideas about?
Just add this in you ViewDidLoad method
self.automaticallyAdjustsScrollViewInsets = NO;
The answer was very funny for me and my team, and worked like a charm
In the Interface Builder, Just move the tableview under another view
in the view hierarchy.
REASON:
We observed that this happens only for the First View in the View Hierarchy, if this first view is a UITableView.
So, all other similar UITableViews do not have this annoying section, except the first.
We Tried moving the UITableView out of the first place in the view hierarchy, and everything was working as expected.
Go to the attributes inspector of the View Controller by selecting the xib or the controller in Storyboard. Uncheck the Adjust Scroll View Insets in Layout. It will solve the problem
If you are using a UITableView with grouped style and only 1 group, use plain style instead solve your problem.
UITableViewController *tableViewController;
tableViewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain];
Simplest solution to this problem in grouped type tableView is:
tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
For solve this problem make sure that you unchecked this field on ViewController:
On ViewController >> Attibutes Inspector >> Layout (unchecked - Adjust Scroll View Insets)
if this is not enough, try this on TableView, set Style to Plain:
This will solve your problem
guys!
I had the same problem. TableView appeared with free space between nav bar and first cell.
This code saved me:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if (section == 0) {
return 10;
}
else return 2;
}
There was a space above the UITableView itself, and also between the cells.
Found my solution in 2 different answers above..posting it again so that nobody misses both solutions.
This removed the space from above :
self.automaticallyAdjustsScrollViewInsets = NO;
and this removed the spaces below the cells :
Setting the 'Style' attribute of the UITableView to 'Plain'
I am working with Xcode 7.3.1, iOS9, and swift 2. I would like to share what worked for me:
Just add this in you ViewDidLoad method
self.automaticallyAdjustsScrollViewInsets = false;
Starting in iOS 7, you automatically get a group header and some space. Compare your app to the Settings app and you'll see. You can work around it by telling the UITableView to set the header height as small as possible. See How to hide first group header.
I realize this was answered a long time ago, but for anyone else running into a similar situation, I'll share what ended up working for me:
If you're using a xib, select the top level view and set 'Status Bar' to 'None' in the Simulated Metrics area of the Attributes Inspector. Fixed my spacing issue right up.
For me this didn't work
self.automaticallyAdjustsScrollViewInsets = NO;
This only caused the table view to sit under the NavigationBar.
What worked for me was to go into my storyboard, and resize my tableView. It seems my tableView had a 20px gap at the top to allow for the statusBar. I scaled it and everything lined up perfectly.
I was seeing this extra space at the top of one of my table views in a very strange situation.
After I added a UIScrollView as the root view of my first controller in my navigation stack, if I presented the next controller as a Show Detail segue, my next controller would have the space above its table view.
The solution for me was to change the segue to Present Modally and everything went back to normal.
The strangest part of the segue changing was that before I added my root view being a UIScrollView, my Show Detail segue was presenting the next controller modally. Yet after I added the root UIScrollView, the Show Detail segue was pushing on the next controller (which was not what I wanted).
Had a similar problem, even setting automaticallyAdjustsScrollViewInsets to NO. This solved for me:
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
{
return CGFLOAT_MIN;
}
I was able to remove the gap between navigation bar and first cell writing this line of code in viewDidLoad()
self.tableView.contentInsetAdjustmentBehavior = .never
I tired this with Static Table Views (Style: Grouped).
In the UIViewController.h iOS9 SDK have a method:
#property(nonatomic,assign) BOOL automaticallyAdjustsScrollViewInsets NS_AVAILABLE_IOS(7_0); // Defaults to YES
is not a property, so
self.automaticallyAdjustsScrollViewInsets = NO;
should be
-(BOOL)automaticallyAdjustsScrollViewInsets{
return NO;
}
I want to find out how to add a UISearchBar to a TableViewController - but not to the table view header.
I am having trouble with my existing search bar disappearing after scrolling in certain scenarios. I have found ways to make the search bar "float", but in a couple of corner cases the search bar still disappears after scrolling.
After googling this issue I have found that some people have taken the search bar out of the table view header to deal with this issue. That is relatively easy if your table view is added to a UIViewController. But how do you add a new view (in this case a search bar) to a TableViewController - that is not a subview of the table view automatically provided by the TableViewController?
iPad app iOS 6
-Thanks
Mike C.
First, use storyboards. Add a UIView object to the table header. Then, put your UISearchBar in the UIView. Also, you will need to make your table view controller the delegate for your search bar. Instead of using the scrollViewDidScroll method (or similar), put your floating code into viewDidLayoutSubviews. This works in all cases. I also call bringToFront because I use a custom section header and need to make sure the table header view always stays on top. The top UIEdgeInset is the height of the tableHeaderView.
viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CGRect frame=self.tableView.tableHeaderView.frame;
frame.origin.y=self.tableView.contentOffset.y;
if (frame.origin.y <= 0) {
frame.origin.y=0;
[self.tableView setContentInset:UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)];
} else {
[self.tableView setContentInset:UIEdgeInsetsMake(48.0, 0.0, 0.0, 0.0)];
}
[self.tableView.tableHeaderView setFrame:frame];
[self.tableView bringSubviewToFront:self.tableView.tableHeaderView];
}
Since nobody from either Stackoverflow, or the Apple Developer's forums responded, I got help from Ron Adams in the Idaho branch of Cocoaheads. Basically, I ended up changing my UITableViewController to a UIViewController and manually adding the tableview and search bar. A little extra work, but it works great!