I have a view controller which contains a table view controller embedded in a container view:
What you see inside the view controller on the left is a container view that embeds the table view controller through a storyboard segue. And like you see in the image, there is also a constraint that specifies a top space between the container view and the above segmented control.
When I launch the application everything is normal and I can see a separation space between the segmented control and the table view cells. But as I scroll down, as you see in the blow picture the table view cells overlap with the segmented control:
By debugging the view hierarchy I found out that the problem is that the cells are displayed even if they are outside of the container view:
What you see in the above pictures are the table view cells and the container view. I've drawn two red lines, one starting from the container view top and one starting from the top of the first table view cell and like you see the table view cells go beyond the bounds of the container view, which means that they are visible even if they are outside of the table view area. Instead, the container view which embeds the table view is below the segmented control and the separation space imposed by the constraints is respected.
Can you try setup clipsToBounds? It can be help.
tableView.clipsToBounds = true
Must be something to do with how you've laid out your constraints. Hard to tell by the pictures.
I set a height constraint to the view that has the segmented control. And set the vertical spacing between that view and the container view to 0.
I uploaded a demo project here.
Related
I have a table view controller with static cells. I’m running on iPhone X and when scrolling, the cells appear to be behind the navigation bar and unsafe area. What is preferred would be a solid orange color in the unsafe area instead of the image presented below. Is this possible? I can’t move to a table view inside of a view controller, which I would then constrain to the safe area, because my cells are static.
You need to use a Container View, so add a View Controller in your storyboard and put a Container View in it-by adding the container view it will automatically create a segue and a view controller delete both.
Now from your Container View create a segue to the Table View Controller and choose Embed.
Last step is to set the constraints for your Container View, the most important for your issue is the top one, set it 0 to the safe area.
I want to have a Table View that occupies the top 5/6ths or so of the screen, and then have a View that occupies the bottom 1/6th of the screen. Xcode won't let me simply drag a View into the Table View (as I already have a static view at the top of the Table View. I'm not really sure why it won't let me do a second one at the bottom...) so I'm setting it up as two separate views located on a single screen. What type of view should I embed the Table View and View in? A Container View? A plain old View? Thanks!
Purpose: I'm trying to create a static View that always stays at the bottom of a Table so I'm setting it up as a separate View below the Table View. Unless there's a better way to get a static View to show up at the bottom of a Table View in addition to the static View I already have at the top of the Table View? I don't want this bottom View to scroll with the Table.
I would like to create such a layout where on scroll the imageview hides and collection view takes whole screen. I tried this but it doesnt seem to work. I am getting the image view correctly but the collection view has gone dark completely on run. I have a content view(UIView) and scroll View underneath. Thank you
EDIT 1 :- The Cells are not getting displayed. But the collection view is displayed in the layout. How to solve this?
EDIT 2 :- Instead of using the collection view directly I used a container view and embedded my collection view in it and it Worked! However I am still trying to figure out how do i scroll the container view to top when i scroll, i.e. push the image view on the back of container view while it takes the full height of the screen.
Okay So I figured it out.
Wreck all of the above. (Though the container view solution is pretty good)
Build a collection View controller from scratch having 2 headers, one is the standard and the other one for the image view.
Make your view controller a delegate of the collection view flow layout delegate and implement function for referenceSizeForHeaderInSection
Do not forget to register for the xib yo have created for the image view header by using registerNib forSupplementaryViewOfKind function of collection view object.
My iOS app view has a cover Image at top (100% width, 30% height) and a Table for the rest of the screen. To acheive this kind of layout, I am using "Container Views" in my view. So I have Two Container Views:
1st Container is normal view controller with UIImage.
2nd Container is Table View Controller. This can have many entries.
When I run this and try to scroll, only the second container scrolls in place. 1st container remains at the top.
How can I make the full parent view to scroll instead of just second view.
(Are container views right bet for this kind of requirement and layout?)
you may create a new cell called "HeaderImageCell", and make the first cell to be "headerImageCell"
"Container Views" is not needed at this point.
I'm trying to add my custom ContainerView to an usual ViewController using StoryBoard (iOS7).
I only have a TableView Controller on this view. If I move the ContainerView inside the TableView it is displayed (but moved with the table items), but if I place it directly on view it is not displayed any more! Any ideas?
There appears to be a bug in Xcode/iOS where if the container view is the first child of self.view in storyboard, it doesn't show. For example when I have:
my container doesn't show.
But if I move the label above the container view in the outline:
Then my container view and the label will show.
UPDATE: Upon further investigation it appears the container view does still show if it is the first child, just much lower than you would expect it to appear. Placing another element above the container view allows the container to appear in the position you would expect (the position shown in storyboard).