[英]Changing label text
I'm developing an iOS application, using Xcode 4.6 to code in Objective-C. 我正在开发一个iOS应用程序,使用Xcode 4.6在Objective-C中进行编码。 I have two screens connected by a push segue.
我有两个通过推键连接的屏幕。 In the first one I have a text field that will be filled by the user, and in the second one I have a label, and I want to fill that label text with the first screen text box text.
在第一个窗口中,我有一个文本字段供用户填充,在第二个窗口中,我有一个标签,我想用第一个屏幕文本框文本填充该标签文本。 I have also 1 class for each screen, so I have the FirstController.h, FirstController.m, SecondController.h, SecondController.m.
每个屏幕我也有1个类,所以我有FirstController.h,FirstController.m,SecondController.h,SecondController.m。
从第一个视图控制器转到第二个视图控制器时,可以在第二个视图控制器中将标签作为属性公开,然后在第一个视图控制器的方法(需要对此进行子类化)期间设置该标签:
Make sure you have a segue created. 确保您创建了segue。 You can then pass the data using:
然后,您可以使用以下方式传递数据:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
SecondController *second = [segue destinationViewController];
second.label.text = textBox.text;
}
If you have the property of your label in your SecondViewController
, you can use prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
method to set its text after creating an instance of the SecondViewController
and calling for its property as 如果您在
SecondViewController
具有标签的属性,则可以在创建SecondViewController
实例并将其属性调用为之后,使用prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
方法来设置其文本。
`secondViewController.myLabel.text = @"some text";
If you have your label as an instance variable, pass the text using an NSString
for the label's text to second view as 如果您将标签作为实例变量,则使用
NSString
将标签文本的文本传递给第二个视图,如下所示:
`secondViewController.txtStr=@"some text";
and in SecondViewController
,set label's text in viewDidLoad
method. 在
SecondViewController
,在viewDidLoad
方法中设置标签的文本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.