Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Malthe Pedersen
Malthe Pedersen
2,338 Points

Refresh data when dismissing viewcontroller

I have a viewcontroller which leads to another viewcontroller with modal presentation. When I dismiss this modal viewcontroller, I want to refresh the data being displayed in the first viewcontroller. How can I do that?

5 Answers

Dominic Bryan
Dominic Bryan
14,452 Points

In your prepare for segue add self.tableView.reloadData(), of course replacing the necessaries such as tableView with the name of your view you are going to.

Hope this gives you an idea.

Dom

Malthe Pedersen
Malthe Pedersen
2,338 Points

So you're telling me that it is not possible to update/refresh/reload a viewcontroller??

Dominic Bryan
Dominic Bryan
14,452 Points

Haha absolutely not, I didn't say that at all you just need to reloadData() in your segue method. What makes you say I said it wasn't possible aha

Dom

Malthe Pedersen
Malthe Pedersen
2,338 Points

Because you said I needed to use a tableview instead :-)

Dominic Bryan
Dominic Bryan
14,452 Points

No no no I said "replace the necessaries such as tableView", so you would use view. reloadData() or what ever your view is called aha

Dom

Malthe Pedersen
Malthe Pedersen
2,338 Points

Ahhh okay :-) The only thing I can do with reload, is this: self.view.reloadInputViews() ?

Malthe Pedersen
Malthe Pedersen
2,338 Points

It didn't work btw.. This is my "prepare for segue" since its a modal; self.dismissViewControllerAnimated(true, completion: nil)