0

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.

Strong Like Bull
  • 11,155
  • 36
  • 98
  • 169
  • You need to give more information about the data model. How is your data organized? What kind of a structure does it follow? If the problem ends here, I would use NSUserDefaults and store a string - end of problem - but this feels mighty wrong to me. – Ravi Aug 14 '12 at 16:43
  • Usually you'd use a delegate protocol to give the child controller a way to provide data back to the parent controller, a la http://stackoverflow.com/a/6204427/1271826 – Rob Aug 14 '12 at 16:46

1 Answers1

0

This is very simple

  1. 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.

  2. 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.

  3. When user clicks the "select fruit" cell in the first viewcontroller, show the FruitSelectionViewController as a modalviewcontroller (using presentModalViewController)

  4. 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)

jake_hetfield
  • 3,388
  • 1
  • 23
  • 30