What type of view to embed a Table View and View into - ios

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.

Related

UITableViewCells are displayed outside of the table view container

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.

How to constrain static table view controller cells to Safe Area in Swift/iOS

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.

Push other views dynamically to below if table view expand/dropdown

When I expand the table view section, I want the other views at bottom of the table view to move down dynamically and when collapse it will move up dynamically. Currently expand it will overlap and hide at the views below. May I know how to do it?

How to add UIButton to UICollectionView which will scroll with its cell?

I was trying to build home base application which mean there are many icon at root view and it will navigate to appropriate view. So, I will use collection view for it. But, the problem is when I add button to the collection view, the button didn't scroll with collection view, when I scroll collection view up. Here is my simulator build:
As you can see,the button "Click here to login" didn't scroll up with collection view. So, is there any way that I can add button to center of collection view which will scroll with collection view?
Here is my storyboard :
What am I doing wrong?
When you take a closer look at your view hierarchy in Interface Builder you'll notice that the button you added isn't actually a subview of your collection view. I added a red line to indicate which objects belong to the collection view.
Your login button is on the same level as your collection view in the view hierarchy. Both are subviews of your view controller's root view. So no wonder the button doesn't scroll with the collection view.
However, you cannot simply add an arbitrary view (or button) to the collection view itself in Interface Builder. You'll need to add a Collection Reusable View first as your collection view header and then add your button to it.
Your storyboard scene in Interface Builder will then look like this:
Please note that you'll also need to add some code to your collection view data source (which will probably be the same as your collection view controller) in order to make this work.

How can you make UITableView a subview of UIView retrospectively?

I have a view controller (subclass of UIViewController, not UITableViewController), with a table view as a subview. I now want to put another view on that screen, but can't resize the table view to not take up the entire screen, or drag in a view above that. It seems that the view can only contain a single table view. I know it's possible to have a table view and other views within the same screen, so what am i missing here?
Take a look at your view hierarchy on left - your view is subview of tableView. And you need to have something like
ViewController.view
|--> view
|--> tableView
And you have
ViewController.tableView
|--> view
Edit
What should you do
Copy (Cmd-C) your Table view. Than delete it
Drag View to your View Controller
Choose View and paste Table view to it (Cmd-V)
Drag View from Table view upwards to root view of Controller
Now, you can position your view and table view however you want

Resources