views:

42

answers:

3

Hi

In my iPhone app, the user will be making multiple NSStrings. Once these are made, I need to pass them to another view completely in the app. How can i do this? All I know at the moment os I can't access objects or variables declared in one view, in another. Thanks.

+1  A: 

One way would be to follow the MVC (model view controller) design pattern. Whichever controllers are responsible for your respective views can then store and retrieve the NSStrings from/to a common data model object.

As to how you can make the strings stored in an object visible to the outside, the easiest way is to use Objective-C properties to save you from writing the accessor methods yourself.

I hope this helps with your problem or at least gets you started in the right direction.

Thorsten Karrer
Any chance of an example? Im not sure where to start, never worked with this before.
Josh Kahane
A: 

Place the strings in a data model object (the M of the MVC pattern), with accessor methods (getter and setters, which can be automagicly created by properties). Then create and place that model object in some central location, a controller common to all views requiring that data, or the appDelegate, a reference for which can be found from any view.

hotpaw2
Any chance of an example? Im not sure where to start, never worked with this before.
Josh Kahane
A: 

Josh,

I would add to the MVC thing, that still you can do this in several ways.

What I would do for example, is to make your other "View Controller" (MVC), to "observe" when does the user create a new string, and to fetch it accordingly. In that way you would reduce coupling and it will be a cleaner implementation.

Another way would be to create a "delegate" so that the First View controller, "notifies" or calls the delegate method that you created, each time the user creates a new string ( again reducing coupling )

Mr.Gando
Any chance of an example? Im not sure where to start, never worked with this before.
Josh Kahane