Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Enhance a Weather App with Table Views Next Week’s Weather Displaying Information in the Table View

Mathis Claßen
Mathis Claßen
4,892 Points

Data Source protocol

I used these functions before without caring to much how they work.

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {}

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {}

"numberOfRowsInSection" and "cellForRowAtIndexPath" are functions of UITableView, they are closures of some sort. After a lot of brainbending I finally understood how completion handlers work, since closures are some kind of "lovecraftian" concept for me [its powerful and huge but trying to understand it makes you insane].

In both functions I do nothing with the provided parameters and only return an Int or an UITableViewCell. I understand that the Class holding these functions is a delegate of UITableView and UITableView calls this functions when needed, populating them with those parameters. Maybe I do not need to know, but how does that all work together.