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

I am trying to change my tableView in relation to changes done in my detailViewController, what is the best way?

I have a tableViewController that when you select a row leads to a detailViewController. In the detailViewController the user can enter info in a textView. I archive this info into an Array. When the tableViewController's viewDidLoad is called, the archived array is unarchived and populates a UILabel in the tableView Row. I want this to happen when I navigate back to the tableView from the detailView but when the popToRootViewController is called it doesn't call the viewDidLoad because it is already loaded. If I do a prepareToSegue it loads the tableView in another position on top of the stack.

Also, this is a swift project.

What should I do?

try view did appear or view will appear and the reload the table view. Not sure how to do this in swift only objective c

Thanks Russell. The viewWillAppear does get called when I pop back. Thanks for getting me on the right track.

I tried to call the reloadData() for the tableview but it doesn't do anything.
To the best of my understanding from the documentation that should update the cell labels. (but it doesn't)

I am doing something wrong.

You would usually reload the data in a table view, if you included something like a pull to refresh feature in your app and you were pulling information from a backend. Then it would have the new data and then you would update all the cells with the new information. Hope that helps :) In objective c you read the data by saying [self.tableView reloadData];

2 Answers

I would suggest to use the viewDidAppear or ViewWillAppear method. As you said correctly, viewDidLoad is only called once. viewWillAppear or viewDidAppear is called every time you bring back this view. So to update content in this view, no matter if table view or normal view, it would be best handed in one of the above. As i said, that´s only my suggestion. I´m sure there will be other solutions out there, but it works nevertheless.

Greetings

Sorry if my answer was late, but when i saw this post a couple of minutes ago there was´t any answer... then when i posted mine, your two showed up ...