views:

114

answers:

2

I have what I hope is a fairly simple question about using the value from a variable across 2 views. I’m new to the iPhone SDK platform and the Model/View/Controller methodology. I’ve got background in VB.Net, some Php, but mostly SQL, so this is new ground for me.

I’m building an app that has 3 views. For simplicity’s sake, I’ll call them View1, View2, View3.

On View1 I have an NSString variable that I’ve declared in View1.h, and synthesized in View1.m. I’ll call it String1. View1.m uses a UITextField to ask the user for their name and then sets the value of String1 to that name (i.e. "Bill").

I would now like to use the value of String1 in View2. I'm not doing anything other than displaying the value ("Bill"), in a UILabel object in View2.

Can someone tell me what the easiest way to accomplish that is?

Many thanks in advance….

A: 

You'd need a "model" part of MVC to keep that value in a variable and register observers in all views for that value so that views could respond to value changes and display it.

Eimantas
A: 

See my answer here for how to build "Model" objects (in the MVC sense) that store data for use by multiple "Views".

Shaggy Frog
Thanks for the reply, Shaggy Frog. I'll have to do my homework on how to implement the model object as simply as possible.
SD