Project Overview
I have a UITableViewController as the root view controller of a UINavigationController. Its view is a UITableView using the UITableViewStyleGrouped style. The table view also has a UIRefreshControl. I am not using nib/xib files, everything is created programmatically.
Problem
The header for the first section in my table view goes under the navigation bar. The refresh control, however, is in the right place. Normally problems with this are caused by a translucent navigation bar, but mine is opaque already.
Attempted Solutions
self.edgesForExtendedLayout = UIRectEdgeNone
This doesn't produce any changes.
self.tableView.contentInset = UIEdgeInsetsMake(20.0f, 0.0f, 0.0f, 0.0f);
This puts my table view in the right place, but causes the refresh control to be adjusted down as well. Not to mention that this is a dirty solution anyway.
Try using:
[self setAutomaticallyAdjustsScrollViewInsets:NO];
You need to use a plain viewcontroller and add the tableview there at the desired position.
This is because in case of an uitableviewcontroller the whole tableview is the parentview . I hope you got my point.
Related
According to Apple the refresh control should be part of the large title navigation bar in iOS 11.
The refresh control is part of the navigation bar (on pull to refresh) when I enabled the refresh control in my storyboard for a UITableViewController.
I can not do this in storyboard for all other views like UICollectionViewController. When I add a refresh control in code as a subview it is not part of the navigation bar:
refreshControl = UIRefreshControl()
collectionView?.addSubview(refreshControl)
It looks like this though:
How can I add a refresh control to my custom scroll view like UICollectionViewController in such a way that the refresh control is displayed in the navigation bar when large titles is used?
As of iOS 10, UITableView and UICollectionView has refreshControl property.
So, instead of:
tableView.addSubview(refreshControl)
you do:
tableView.refreshControl = refreshControl
and this should work for new big headers in iOS 11.
EDIT: The documentation has been updated at some point, and below information is not longer true.
As specified by Apple in UIRefreshControl documentation.
Note
Because the refresh control is specifically designed for use in a table view that's managed by a table view controller, using it in a different context can result in undefined behavior.
If your VC is a UITableViewController it will work exactly like in system apps.
In my case, I wanted to have UIView under UITableView, so UITableView wasn't first subview of view controller's view.
To fix this, I changed order of UITableView and other UIView
from
to
Now I just set zPosition of my view to lower value than UITableView's zPosition which should make my view look like it is "under" UITableView
myView.layer.zPosition = -1
I have a UITableView that when first displayed it displays correctly with the first row appearing on top. When I select a cell another UITableView is presented. If I used the back button on the UINavigation Bar the original UITableView is shifted down with a blank space between the UINavigation Bar and the UITableView.
I am not using story boards. I am using XIB files. I am also using a sliding menu that I got the code for from Ray Wenderlich's web site.
When I slide back the main screen over the first UITableView it goes back to its proper position. But then when I select an entry again the issue described above appears.
I found another post that seems to provide an answer to the issue. This post says to make some adjustments like to the translucent settings or the auto-layout settings but doesn't give specifics.
Here is that post: Container View getting pushed down as if it had a UINavigationBar?
Thanks,
Glenn
Add
self.automaticallyAdjustsScrollViewInsets = NO;
in viewDidLoad, of the UIViewController where you have the shifting table view
I'd like to add a segmented controller to a navigation bar, below the title.
At the moment, I've got a storyboard UITableViewController with a CoreData-sourced dynamic table, embedded in a UINavigationController. I'd like the UISegmentedController to differentiate the sorting of the table.
There seems to be obj-C solutions available stackoverflow.com/questions/29480433/ and stackoverflow.com/questions/18813563, but I'm looking for a Swift solution, that resembles the native apps. I've also tried putting the segmented controller into a table cell with little success (can't get the action recognised). I'd prefer not to abandon the table view controller.
Any suggestions?
I replaced the UITableViewController with a UIViewController and UITableView, then added the UISegmentedController to a UIToolBar positioned below the UINavigationBar.
I used removeShadow for the navbar, then clipsToBounds for the toolbar. I also added another View to simulate the bottom shadow on the toolbar (because I couldn't get the toolbar shadow/background position function to work).
I have an application where I have a UITableView with sections which are scrollable on the side through sectionIndexTitlesForTableView:.
In the tableHeaderView of the UITableView I want to add a UISearchBar, which I want to behave like the one Apple is using in their new Contacts app in iOS7. But I can't seem to get it to work.
The search bar is not 100% the width of the screen, but instead has its right side against the section index.
My questions are:
How do I get the search bar's width to 100% when it's the tableHeaderView of a UITableView that has a visible section index?
How can I create a transition like in the Contacts app of iOS 7 where the navigation bar hides and the search bar's grey background extends to the status bar?
I have tried several things already, including adding the search bar in the navigation bar, and using UISearchBarController, but I can't find good documentation on the Apple website on how to create this. Also, the transition guide from iOS6 to iOS7 has been no good help for me.
Here are two pictures that illustrate my problem:
Two main differences to the way Apple do their app, which will solve your problems.
First, their UISearchBar isn't the headerView for the tableView. It's a separate view above the table. You'll need to change your UITableViewController to a UIViewController that has a UITableView positioned just below your UISearchBar.
Second, their UISearchBar has an associated Search Display Controller. Assuming you're using a storyboard file, this comes bundled together for you - just add the UISearchBar with the Search Display Controller. This will handle all of the transitioning to underneath the status bar for you.
Two things:
1) Set tableView's sectionIndexBackgroundColor to [UIColor clearColor].
2) Implement 'viewDidLayoutSubviews' method to fix frame for UISearchBar
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
CGRect barFrame = self.searchBar.frame;
barFrame.size.width = self.view.bounds.size.width;
self.searchBar.frame = barFrame;
}
I'm trying to achieve to display a toolbar on top of a tableview. I'm working for iOS5 with storyboards I need a toolbar because it needs to be customized in a way a navigation controller does not allow me to do.
The following image shows what I want to achieve:
The left and right white arrows are what I think I can't achieve with the use of a navigationcontroller. Right now I got to display everything (The screenshot is from the iphone simulator), but my problem is that the toolbar scrolls with the table, and I would like it to stay on top. I think this is because of the way I wired up things in the storyboard. Next image shows a snapshot of what the view looks like in storyboard:
The controller is a subclass of UITableViewController. The toolbar is inside the tableview because the StoryBoard editor did not allow me to put it anywhere else.
I've tried to create a new generic view controller from the storyboard, drop a toolbar and a tableview and then set the type of the controller to my custom UITableViewController. Then the storyboard does allow me to have the toolbar on top and then the tableview. The problem is that when I run this version the program terminates with a
libc++abi.dylib: terminate called throwing an exception
So right now I don't know what to do. Is there any way I can make the toolbar stay on top? Can I accomplish my objective with a navigationcontroller (using storyboards) and thus make things easier?
Any help will be appreciated. Thanks.
Depending on how you want to behave, stationary or scrolling. You can add a subview to the
UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0, 44, 320, toolbarHeight)];
[self.navigationController.navigationBar addSubview:myView]
In 'myView' you can add all the buttons you need. Then you can leave the first cell empty.
Instead of using a TableViewController I would start with a simple ViewController then add a TableView and a Toolbar. It's going to take more code but I don't see how any of the "template" controllers will let you do what you want.