开发者

Obj-C Global Strings & Variables

There's some way to declare 开发者_JAVA百科Strings and Variables in Obj-C for iPhone? I mean, i want to display the data input on textfield in 01.xib on 02.xib label's.

How can i do that?

Thanks!


You'll need a class that communicates between the two, getting the relevant value from the textfield in your first XIB and setting it as the value of the label in your second. This is quite a basic sort of operation, so I guess that hints and keywords are the best way forward.

Your first XIB will have a class nominated as 'File's Owner'. That should match a class in your Xcode project. Things defined in Interface Builder access one another through outlets. So you at least need an outlet from the owner to the text field. You may also want it to be the text field's delegate, depending on what means you're using to decide to move from the one NIB to the other.

Much of the time, iPhone people set the File Owner of a NIB or XIB (the terms are interchangeable) to be a subclass of UIViewController. So probably you'll have an outlet to both the text field and the view controller that owns the second XIB. General program flow will be that, upon the relevant event, it reads the value of the text field, communicates it to the other XIB and then presents the other XIB.

Similarly, the second XIB's owner (another UIViewController, probably) will have an outlet to the label and will use that to set the value.

Interface Builder is for drawing out the interface and connecting objects to define who knows about who. Xcode is for writing actual code. If you stick to model-view-controller then Interface Builder helps you draw the view, then you code up the controller and model for yourself. UIViewController subclasses are, as the name suggests, meant to be in the controller layer. Objective-C is another language derived from C (which, unlike C++ or C# is a strict superset) with many of the same ideas about semantics.

It's difficult to elaborate on any of that without elaborating on all of it and writing about 20 pages.


Two view controllers are the owner of the two xib file. They should have property declaration for UITextField and UILabel.

(02.xib'x label).text =  (01.xib's textfield).text;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜