-1

So i've seen many questions alike mine, but all don't have the working answer, or have vague answers (and none of them marked as correct).

I have two ViewControllers:

ViewController #1 has 4 textFields to which there are pickerViews attached in order to choose an option to fill in the textfield. Also there is 1 textView in which the user can use the keyboard.

To sketch the scenario: Label states: 'Pick a color:' User clicks on the textfield (pickerView shows up full of names of colors) user selects 'red' and the picked choice shows up in the textfield below the label: 'pick a color'. Then when all textfields and textview are filled in, the user clicks save. In which the save button redirects the user to the 2nd ViewController.

ViewController #2: This is where i want the input (of the textFields and textView) to be shown in the labels(if this is the correct usage). Since this is where the user will see list of the chosen answers. However i cannot manage to get this working.

What do i need to do in order to achieve this?

Also i'm still learning. Please bear with me. Thanks in advance.

Anna_JB
  • 11
  • 1
  • 10

1 Answers1

0

In general this site is not well-suited to "Tell me how to do XYZ" type questions. It's intended for getting help with code you have already written. You're new, though, so I'll take pity on you.

You should post the code that you have, showing how you get from view controller 1 to view controller 2.

I'm going to assume that you have a segue from view controller 1 to view controller 2.

(You should probably have code that disables your send button until all 4 text fields are filled in with valid colors.)

Anyway, let's assume that your send button triggers a segue, either directly, or in an IBAction that triggers a segue through a call to performSegueWithIdentifier.

You need to define properties for your 4 color strings in view controller 2.

Then, add a prepareForSegue method to view controller 1 if you don't have one already. In prepareForSegue, make sure the segue matches the segue identifier that invokes view controller 2 (good idea even if you only have 1 segue now, since you might add more segues later.)

ViewController2 *vc2 = (ViewController2 *) segue.destinationViewController;

Assuming it's the right segue, get a pointer to the destination view controller and cast it to the type of ViewController2 so you can refer to your color properties.

Then use code like this to pass the colors to view controller 2:

vc2.color1 = myColor1TextField.text;
vc2.color2 = myColor2TextField.text;
vc2.color3 = myColor3TextField.text;
vc2.color4 = myColor4TextField.text;
Duncan C
  • 128,072
  • 22
  • 173
  • 272
  • Thank you, atleast not all people are beasts in helping the new. I indeed have a send button to go from vc1 to vc2. do i add the segue code in the viewdidload? – Anna_JB Dec 04 '15 at 07:41
  • You send the values to the destination in `prepareForSegue`, and then install them into your views in either `viewDidLoad` or `viewWillAppear`. `viewWillAppear` is usually safer because that gets called even in cases where you keep a view controller around and display it more than once. – Duncan C Dec 04 '15 at 11:36
  • Also, by the time `viewWillAppear` is called, your views have been sized to the current device. In `viewDidLoad` the views have not been adjusted for the current screen size and orientation. (e.g. you might lay out your views in iPhone 6 portrait size and display them on an iPhone 5, and in Landscape. In `viewDidLoad` the views will still be set up for iPhone 6 portrait. in `viewWillAppear`, they will have been adjusted for the current setup of iPhone 5 landscape.) – Duncan C Dec 04 '15 at 11:37