UITableViewController within UIContainerView - ios

I have a static UITableViewController embedded within a UIContainerView. All created using Storyboards.
I'm setting the positioning of the container view using autolayout, whereby it is always touching the top, left and right of the uiviewcontroller it is within and always 50px from the bottom due to a UIButton being there.
The UITableViewController has a larger content size than the height of the container view, so one would expect you to be able to scroll the tableview from the container view.
But for some reason I cannot get it to work, when you initially load the UIViewController the scroll indicator appears and then hides and it won't let you scroll the tableview. How would I solve this?
(It has previously worked for me, I just can't remember what I did.)

Related

UICollectionView embedded in UICollectionViewCell acting weird with UINavigationController

I have a UINavigationController that has a UIViewController at its root. I have a UICollectionView that fills the UIViewController. My look that I'm trying to go for is a navigation bar that hovers over this collection view. For this I have pinned the UICollectionView to the top of the superview instead of to the top of the Safe Area. I've also turned off adjust scroll view insets.
Inside my collection view I have a cell that has a UICollectionView embedded in it. When I start scrolling, the embedded UICollectionView seems to decrease in size slightly as it goes past the UINavigationBar. I should note that if I instead pin my outer UICollectionView to the Safe Area, this problem doesn't occur!
How can I solve this? Is there a better way to make the UICollectionView ignore the nav bar instead of pinning it to the top of the superview?

UIPageViewController in Contrainer View

I am trying to embed UIPageViewController into Container View. The ContainerView has the following layout:
It consists of UIViewController which holds Container View and 2 buttons at the bottom.
The connection between Container View and UIPageViewController is established through "embed segue".
UIPageViewController manages 3 UIViewControllers. Each UIViewController represents app walkthrough tutorial screen, and has the following layout:
The Problem: When I run the app, the first walkthrough screen looks as it is supposed to, meaning all the layout elements are displayed properly:
However, when I scroll to the next walkthrough screen only UIImageView is displayed, pushing down the other two labels, that are below it, out of the frame:
I was wondering how can the Container View display all elements of the UIViewControllers managed by UIPageViewController?
You shouldn't set the imageView's bottom constraint to 0. You should constrain it to the heading's top anchor. Similarly you should set the bottom of the heading to descriptions top. And set the descriptions bottom to its superview's bottom.
I have solved this issue by putting the contents of tutorial screen inside vertical stack view, and giving the UIImageView lesser Content Compression Resistance Priority

scrollview within a containerview in storyboard not scrolling

I have a viewcontroller with one UIView on the top and a containerview placed right beneath it. Like,
I'd connected everything with Autolayout.
Now, I want to load 4 different containerviews in that bottom space(one over the another, since at a time I'll show one containerview only and will hide the rest using alpha property of a UIView), of which one of the containerview has so many subcomponents(registration page comps), for which I used a UIScrollview. The scrollview is not working in this scenario, my question is,
Can I use a scrollview within a containerview?
My scrollview has a UIView in it, which inturn holds the individual components, is that the reason why my scrollview is not working?

Why content insets of a UITableView inside a UIPageViewController get messy right after an interaction?

I've created a Page-Based Application and hacked it a bit for some experiments; my simple aim is to have a UIPageViewController whose pages will contain a UIViewController holding a UITableView (after further inspection, the outcome of my experiment is the same if I use a UITableViewController instead).
To do this I've simply edited the project template, and added the UIPageViewController as an embedded view of the RootViewController using Storyboard's ContainerView object, as you can see in this screenshot:
Every controller is configured via storyboard to automatically adjust scroll view's content inset, and if I start the project with this configuration everything looks fine, and the DataViewController's tableview has its content insets properly adjusted right under the navigation bar as expected; however, as the user makes an interaction with the tableview, the content insets break and the tableview underlaps the navigation bar:
I have been able to fix this by manually setting the content insets in DataViewController's viewDidLayoutSubview method, and by disabling Adjusts Scroll View Insets on any controller, so I don't need this as an answer to solve my problem.
My question is why the content insets are properly set right after the first controller gets loaded from the storyboard the first time, and why they break after any kind of user interaction.
If you need to test it directly, here's a link to the project
I'm not 100% sure it's what you're running into, but here's some explanation regarding your setup:
By default, UIViewControllers tend to be configured to extend their content behind non-opaque bars, and to adjust scroll view insets. In your setup above this means that the container VC:
Extends its content so as to appear behind the navigation bar
Sets its scrollview's .contentInset and .scrollIndicatorInsets to be the same height as the navigation bar
"But, ah!" I hear you say, "that container view controller doesn't have a scroll view". Well this is the tricky bit:
It seems UIViewController's definition of "my scroll view" is rather simplistically, "the first scroll view I come to when searching down through my view hierarchy".
UIPageViewController happens to be implemented using a scroll view. So the container VC finds that scroll view, and adjusts its top insets. This is not really what you want; it confuses the page controller, and tends to upset layout at some point.
The simple solution there is simply to turn off .automaticallyAdjustsScrollViewInsets for the container view controller.
You then need to solve the next problem of your table view needing some kind of top insets to account for the navigation bar. So far it seems to me the best way to do this is manually either in the storyboard, or code.
Found an elegant solution:
From your storyboard, select your UIPageViewController
In the Attributes inspector, uncheck the option ViewController => Extend Edges => Under Top Bars
That's all, no weird UI hacks
Have you tried fixing the Auto Layout constraint in the container view of the Root view controller in the Storyboard (that is, the top space constraint should be set related to the Top Layout Guide and not the Superview, with constant = 0)?
You will only lose the effect of the Table View scrolling under the Navigation Bar

iOS: Stretching ImageView Above My TableView?

I have added a UIImageView on top of my tableView in storyboard & it works perfectly fine, except that when you scroll down, the imageView doesn't stick to the navigationBar and instead only sticks on to the tableView (revealing the view's background above it).
How would I get it to stick to both the tableView and the navigationBar, and just have the imageView stretch/zoom as the user pulls the tableView down?
This is how it's set up in storyboard:
And this is how I assign an image to it in my ViewDidLoad:
childHeaderView.image = [UIImage imageNamed:headerImage];
Any help would be greatly appreciated. I've tried setting constraints on it using autoLayout but it doesn't seem to let me (they're grayed out, even though I've enabled it for that ViewController).
The problem is that what you did in storyboard is adding the UIImageView as a header to your UITableView.
The proper way to do this is to add the UIImageView at the same level as the UITableView, which mean embed these two views inside a UIView.
Having a UIView as a root view for a view controller is unfortunately impossible for a UITableViewController, and I fear that this is your case. So you may want to replace your UITableViewController subclass by a UIViewController subclass.
EDIT: You'll want to set a fixed height constraint on your UIImageView, and add a vertical space constraint with a 0pt value between your UIImageView and UITableView.
Most of these can be achieved by moving view in IB.

Resources