开发者

iPhone SDK Programming - Working with a variable across 2 views

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 mos开发者_运维百科tly 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….


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜