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 Introduction to Table Views High Level Overview of Table Views

Chengyu Deng
Chengyu Deng
7,879 Points

How do we know xcode will execute n times which n is the total number of rows?

How do we know xcode will execute n times which n is the total number of rows? The cellForRowAtIndexPath method only returns a single cell which has a specific indexPath. But when we run the project, all the fruits' names are assign to the corresponding rows. Is there any loop executed behind the scene? I am a little confuse... Please help!

1 Answer

Steven Deutsch
Steven Deutsch
21,046 Points

Hey Chengyu Deng,

Your UITableView has a method that takes an argument of number of rows in section.

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return itemsOfArray.count
    }

You use the count property on the array you are displaying in your masterView and return the number of items in that array. This lets your tableView know how many rows it needs to create.

Good Luck

Chengyu Deng
Chengyu Deng
7,879 Points

Yeah, I know there is a method which returns the number of rows in section. In the master view controller, we are simply writing some methods for this class. I was wondering how this methods are called when the project is running. Thanks!