Create a registration form within a storyboard for iPhone and iPad. This is done using a static table in Xcode. Static tables are used throughout the settings app.
Start with a single view project with a Table View Controller. Create a registration table using a static form. This will allow you to gather useful information from the users of your iPhone app.
Using a static table to create a form is just one use case, it can be used for a wide range of scenarios in your iOS app.
Amit: Hi, I’m Amit and in this Treehouse quick tip we’re going to learn how
to create a form using a static table with an eight story board. Static
tables are used throughout the settings app on an iPhone or iPad. Let’s
learn how to create one.
Let’s start with a single view project and make sure that the first view
controller in the story board is a table view controller. As you can see,
this is a regular view controller. We will delete this and add a table view
controller. We will also make sure that the view controller .H inherits
from UI table view controller. Going back to the main story board, the
first thing we will make sure is that our table view controller connects to
our view controller, which is this view controller .H . So make sure that
the table view controller is selected here in the hierarchy viewer and
enter class view controller. So now our table view controller is connected
to the view controller. When you first select the table view, opening up
our hierarchy view, you can select table view, you will notice that it is
selected to have dynamic prototype as its content. Going over to the
attributes inspector and you will notice that the content says dynamic
prototypes. We can change this to static cells because dynamic prototypes
is when you are providing it with data and then dynamically creating rows
within this table to fit that data.
So let’s find out how to quickly create a registration form using the
static table. Now a table is made up of cells, and the grouping of the
cells is known as a section. And we can also change the style of the table
so we can go from plain to grouped, so as you can see the style changes
over here, and we can also provide a section with our section header. So
if you click on table view section in the hierarchy view, you can go ahead
and change the header. I’ll call this “header registration”. So as you can
see, we now have a header, and each cell can have several different styles
as you can select from the styles in the attributes inspector but let’s
keep it as custom, and we will add a label and a text field for our
So searching for label in the box down here, we will take the label and
drag it to our cell, and next I’ll search for text field and take the text
field and once again, drag it to our custom cell. So I can call this
“label name”, and similarly I can duplicate this cell and have another
field called “email”. Since these are text fields, I can customize the
return key which is under return key and instead of default, I can select
“next” and for the email one I can select “done”.
And finally, what you want to do is now that you have these custom text
fields in your custom table view cell, you can add IB outlets to your view
controller. So basically going over to the assistant editor, let’s make
some room. Holding down the control key you can drag it to the interface
and create IB outlets. And if you run this application, you see you can
now enter information and capture it programmatically. Using static tables
to create a form is just one use case. You can use it for a whole wide
variety of scenarios.
Announcer: If you’d like to see more advanced videos tutorials like this
one, go to TeamTreehouse.com and start learning for free.
Comments are closed.