Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add button on top of UITableViewController (Swift)

I am trying to add a button ontop of a uitableview controller table view. The view controller has a navigation controller and static cells, which is why it is a uitableviewcontroller and not a uiviewcontroller. Now I am trying to add a button at the bottom of the screen that is attached to the navigation controller so that it doesn't scroll with the table view.

I am trying to make something similar to what is below. It has a navigation controller for the top bar, a table view with static cells and then a button, but how did they do the button?

Image: http://postimg.org/image/ilsmqqrip/

Thanks!

UPDATE: How can I use a uiviewcontroller with a tableview with static cells using Swift?

like image 382
zach Avatar asked Jul 13 '15 19:07

zach


People also ask

How to add button on top of tableview swift?

Just create a normal UIViewController, add your button and a ContainerView as subviews of this UIViewController (the middle one in the image below). Finally create Embed Segue from ContainerView to your UITableViewController (the one on the right).

How do I add a navigation bar in Swift storyboard?

Go to the Storyboard. Select the View Controller and in The Editor menu select Embed in -> Navigation Controller. Next, drag a Bar Button from the Object Library to the left side of the Navigation Bar and name it "Left Item". Repeat this for the right side and name it "Right Item".


1 Answers

I find Container Views very useful in this scenario! A clean solution and very easy to implement.

Just create a normal UIViewController, add your button and a ContainerView as subviews of this UIViewController (the middle one in the image below). Finally create Embed Segue from ContainerView to your UITableViewController (the one on the right).

Storyboard

This way you can use static cell prototypes, not being limited only to UITableView at the same time.

Result:

Result

like image 102
andrew-frank Avatar answered Sep 30 '22 17:09

andrew-frank