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 Custom Table View Cells Pull To Refresh

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

refreshControl

@IBAction func refreshWeather() {
        retrieveWeatherForecast()
        refreshControl?.endRefreshing()
}

To my understanding in this case the refreshControl does not wait for retrieveWeatherForcast() to finish. The animation will stop immediately even if the request takes some seconds, right?

2 Answers

Yes. The call to endRefreshing() should be inside the closure, after the end of network operation.

Remove it from refreshWeather() and just add self.refreshControl?.endRefreshing() (don't forget the self) after self.tableView.reloadData() in the method retrieveWeatherForescast(). This is the correct implementation.

Thought the same thing. I think it's a better implementation to call refreshControl?.endRefreshing() at the end of the retrieveWeatherForecast method.