I have several UILabels that have certain values within them. When I switch to a different viewController and comeback to original view I lose my UILabel’s values. How do I retain information while switching through two viewControllers?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best answer I can give with the information you provided is to use
viewWillDisappearto save the values of the labels to properties on your viewController. However, how did the information get into the labels? The best thing to do, would be to save the values to the properties on your viewController when the information is somehow set on the labels. Then, you should have some code that populates your labels from your backing properties inviewWillAppear. That way, you’re not storing any state in your UI (which is bad) and you have a single direction of flow of the information/state in your viewController (i.e. you’re not entering information into a label and also pulling information out).