我如何在 iPhone 中为 UILabel 提供输入 [英] how can i give input for UILabel in iPhone

查看:19
本文介绍了我如何在 iPhone 中为 UILabel 提供输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个班级.在我的第一堂课上,我有一个标签.现在我必须从我的第二堂课中为该标签提供输入.这是我的代码.

i have 2 classes . in my first class i have one label. now i have to give input for that label from my second class. here is my code.

 IBOutlet UILabel *label1;

@property(nonatomic, retain) IBOutlet UILabel *label1;

@synthesize label1;

我这样称呼这个标签.我导入我的 class1 并创建像 classone 这样的对象.我检查了(NSLog 打印)类,该方法将被调用,但该输入不会来.我检查了该标签也连接到我的类.因为我在我的 viewDidLoad 中提供了相同的输入 那个时候它工作正常.

I call this label like this. I import my class1 and create object like classone. I checked(NSLog print)class and that method will be called but that input won't come.i checked that label its also connected to my class.because i give same input in my viewDidLoad that time its working fine.

 NSString *ram= @":13123123312";
        classone.label1.text= ram;

指导我哪里做错了.

推荐答案

设置先前视图的值比这更棘手.操作系统在内存压力下删除了什么视图?

Setting values of previous views is trickier than this. What it the view has been removed by the OS under memory pressure?

设置这些值的正确方法是使用在整个 Cocoa 框架中使用的 MVC 模式.您的第二个视图控制器设置了前一个视图控制器的属性.当需要显示之前的视图时,它会从这个属性中获取它的值.

The proper way of setting these values is to use the MVC pattern that is used throughout the Cocoa frameworks. Your second view controller sets a property of the previous view controller. And when the previous view needs to be shown, it takes its value from this property.

正确连接视图控制器以与堆栈中较低的另一个视图控制器对话的常用方法是使用委托协议.

The usual way to correctly hook up a view controller to talk back to a another view controller lower in the stack is to use a delegate protocol.

我写了一个这样的例子,DelegationExample,不久前它展示了第一个视图使用委托协议由第二个视图控制器中的文本字段值填充.您可能会发现,看看我是如何做到这一点的示例很有用.

I wrote an example of this, DelegationExample,a while ago which shows how a textfield in the first view is populated by a textfield's value in the second view controller using a delegate protocol. You might find it useful to see how I have done this as an example.

更新

我已经更新了一个带有 ARC 和 Storyboards 的 iOS6 新项目的链接

I've updated the link to a new project for iOS6 with ARC and Storyboards

这篇关于我如何在 iPhone 中为 UILabel 提供输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆