I am trying to implement a choice system whereby a user can click on a cell in a UITableView called “Select fruit” and then it takes you to another UiTableView that has the fruits selected. After selecting a fruit, I want the user to go back to the original UiTableView but this time the title of the cell says “Apple or Orange” as opposed to “Select Fruit”.
I know how I can implement that by using singleton etc 🙁 but was thinking if there was a simpler way.
Any tips would be appreciated.
This is very simple
Put your UITableView with the fruits in a new UIViewController subclass, lets call it FruitSelectionViewController. Also add a member variable to it called “delegate” or “parent” or something appropriate.
Create an instance of the fruitcontroller in your first viewcontroller (the one holding your “select fruit”-cell) when it loads. Also set this first viewcontroller as the parent or delegate of the newly created FruitSelectionViewController.
When user clicks the “select fruit” cell in the first viewcontroller, show the FruitSelectionViewController as a modalviewcontroller (using presentModalViewController)
When the user selects a fruit, dismiss the modalviewcontroller (using dismissModalViewController), and change the text of the cell to the name of the selected fruit. (you can report this value back to the first viewcontroller by passing it through a method accessed through the parent member that you set in step 2)