I have two classes, Step1 and Step2. Step1 contains a textfield called wrp. When the user enters a number in wrp in Step1, I would like to be able to work with it in Step2. Here is what I have tried (this is code in Step2):
int AdditionalDays;
Step1ViewController *wrp1 = [Step1ViewController new];
UITextField *wrp = [wrp1 wrp];
AdditionalDays = [wrp.text intValue];
TotalTotal.text = [[NSString alloc] initWithFormat:@"%i", AdditionalDays];
The app does not throw an error message, but the user-entered number in wrp in Step1 is disregarded in Step2. I don’t know why it is not working. Any suggestions?
In the line
Step1ViewController *wrp1 = [Step1ViewController new];you are creating a new instance ofStep1ViewController. What you need to to is get a reference to the original Step1ViewController the user entered the text in.To do this, you would probably create a property in your Step2ViewController where you can pass in either the Step1ViewController, or even better, the value the user entered.
So in your Step2ViewController class header, add a property like this:
Then, when you create the Step2ViewController to display it on screen, you set this property to the value the user entered, like this: