Xcode:将文本从文本字段添加到标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9472099/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode: Add text to label from textfield
提问by user1236470
Im working on my first iPhone application, and i would like to add text to a label from a textfield by clicking a button. The thing is that when i press the button the label gets the same value as the textfield.
我正在开发我的第一个 iPhone 应用程序,我想通过单击按钮将文本添加到文本字段中的标签。问题是当我按下按钮时,标签获得与文本字段相同的值。
Textfield value = blabla -> Label value = blabla
文本字段值 = blabla -> 标签值 = blabla
The thing i want is if i change the textfields value to "bla" and press the button again i want the labels value to become "blablabla". I want it to ADDtext to the label not to changeto the same as the textfield.
我想要的是,如果我将文本字段值更改为“bla”并再次按下按钮,我希望标签值变为“blablabla”。我希望它向标签添加文本,不要更改为与文本字段相同的文本。
-(IBAction)ord1 {
label.text = textField1.text; <-- Have to change this line?
[textField1 resignFirstResponder];
}
How do i do that :D?
我该怎么做:D?
回答by Art Swri
Is this what you're trying to do? Concat the text field to the label's text?
这是你想要做的吗?将文本字段连接到标签的文本?
label.text = [NSString stringWithFormat:@"%@%@", label.text, textField1.text];
label.text = [NSString stringWithFormat:@"%@%@", label.text, textField1.text];
回答by Mathi Arasan
NSString *labelstr = @"Your text for a label";
urlabelname.text = [NSString stringWithFormat:@"%@%@",textfieldname.text,labelstr];