- Recognize UITableView as a display pattern and learn more about customizing it.
- Learn how to implement sections (with headers) in a table view.
- Stimulate thinking about how custom objects can be displayed using a tableview.
We've been working with tableviews, but so far we've only put out a unified list based off a single array. Let's get into sections as well as displaying custom objects.
- Open the project โ there's already a blank tableview linked to a custom class set up for you.
- Make a
FISStudent
class with a publicNSArray
property calledfavoriteThings
. - In
FISTableViewController
, make an array property calledstudents
. - In your tableView controller's
viewDidLoad
, make someFISStudent
s and give them allname
s. Then fill in theirfavoriteThings
properties with strings of their favorite things. No specific amount necessary, be creative or simply ask people around you! - Set these students to your TVcontroller's
students
property. - Set up your tableView to match the following:
- each student should have their own section (hint:
numberOfSectionsInTableView:
) - set up
tableView:numberOfRowsInSection:
so that the rows in each section match that student'sfavoriteThings
. - set your cell's
textLabel
to a favorite thing, and itsdetailTextLabel
to its row index.
- each student should have their own section (hint:
- Cool, everyone's favorite things are listed, but theres no distinction between sections... implement
tableView:titleForHeaderInSection:
.using the student's
name` property. - Houston, we have sections! But this is still kinda hard to read, it's just a big list of text after all. Implement
tableView:indentationLevelForRowAtIndexPath:
to clean it up a bit.
Add the following properties to your FISStudent
:
favoriteFood
favoriteColor
favoriteMusicalArtist
favoriteGame
Set these for your student objects in your viewDidLoad
. Now instead of using favoriteThings
in your tableView data source, have it use these new properties to fill in the rows.
Then if you wanna make it real fancy, include the property name in the cell (eg "Food: Pizza" as opposed to "Pizza")
View Tableview Sections on Learn.co and start learning to code for free.