简体   繁体   中英

Best way to update data in a previous view controller in a UINavigationController stack

I have a UINavigationController that adds muliple custom view controllers on top of it in its stack.

The first controller is a custom view controller that has a list of questions. Each question has a agree or disagree text with the count.

So the UI is like so:

What is question 1?
2 agree, 10 disagree

Who is this question 2?
3agrees, 0 disagress

and so on...

When a user clicks on the text for a question, the code does a pushViewController to the FullQuestionViewController. This controllers shows questions and comments. The user can also now click on the agree or disagree buttons.

Now once the user clciks agree/disagree, how do I just update the previous view controller counts? I want the counts to be updated when the user clicks on the

How is this accomplished?

You can put this code in FullQuestionViewController when you have to update to the new value . new_value is the value you want to update to.

CustomViewController * custom = self.navigationController.viewControllers[self.navigationController.viewControllers.count -2] ; custom.myCountVariableLabel.text = new_value // new_value that should be update

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM