2

I've searched and searched but nothing has really worked.

I'm trying to set a textvalue from a text box, into a string or whatever, so that I can call it up later in a different view controller. I can't seem to get it to work!

I'd also like numbers to be carried over, such like currency's.

Any ideas on them?

Cheers.

5 Answers 5

6

You could make an instance variable on the other view controller retain or copy the value before you push/pop the view. For example:

OpenNextViewController *varNextPageController = [[OpenNextViewController alloc] initWithNibName:@"OpenNextViewController" bundle:nil];
varNextPageController .textString= self.textString;
[[self navigationController] pushViewController:varNextPageController animated:YES];
[varNextPageController release];

In "OpenNextViewController" in this example have an instance variable "textString" that retains or copies (depending on your needs) your text.

Sign up to request clarification or add additional context in comments.

1 Comment

Yup, I'm doing something similar in my project. Just pay close attention to retain vs copy.
3

Spend some time trying to grok the Model View Controller pattern.

In your case you may be looking to share data between different views sharing a common Model. The Model is the store of your data, in your case the textvalue.

Comments

0

Your question is a bit vague. Could you give any more specifics. It sounds like you want to know:

  1. How to get values from controls. In the case of a text field there should be a text property you can get the value from.

  2. How to share values between controllers. Not sure exactly what you mean. The controller usually orchestrates the sharing of values between different views by using a model as the authoritative version of the data.

Again, if you can be any more specific we may be able to help more

2 Comments

Right, I've got about 3 view controllers. each with their own view. On the first view controller I've got a text field, I can get the text out from it using NSString *variable and whatever, but I don't know how to get this string over to another view controller where I want to bring it up.
looks like you have an "accepted" answers now - but from what you've said it does look like you're missing a "model" concept (as also highlighted by some other answers).
0

If you want it in several controllers, then I would think you need to run it through the model?

Comments

0

Do you guys think that using the AppDelegate as the holder for one's model is fundamentally wrong? I mean AppDelegate is easily visible to all controllers so it's easy to bind to and get/set it's properties.

pom

1 Comment

I'd recommend asking this as a separate question to get answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.