tags:

views:

1516

answers:

5

Hello, 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.

A: 

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

Phil Nash
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.
Domness
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).
Phil Nash
+2  A: 

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.

Paul Robinson
+3  A: 

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.

Sean
Works perfectly :) thanks!
Domness
Yup, I'm doing something similar in my project. Just pay close attention to retain vs copy.
Sean
A: 

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

le dorfier
A: 

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

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