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

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)