在iOS中将两个文本字段添加/串联到一个标签中 [英] Adding/Concatenating two textfields into one label in iOS

查看:105
本文介绍了在iOS中将两个文本字段添加/串联到一个标签中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个视图控制器中有两个文本字段,例如name和Initial,我想在另一个视图控制器中将它们都显示为一个标签.我该怎么办?

I have two text fields, say name and initial in one view controller and I want to display both as one label in another view controller. How can I do this?

推荐答案

假定这是您的first Viewcontroller

这是您导航secondVIewcontroller

- (IBAction)btnSignUp_touchUpInside:(id)sender
{

SignUpViewController *vc=[[SignUpViewController alloc]init];  //addyour secondviewcontroller
 vc.strFromUnlinkPage=[NSString stringWithFormat:@"%@. %@",yourinitialtextfield.text,yournametextfirld.text];    // here we concatennating 2 strings
 [self.navigationController pushViewController:vc animated:YES];

}

这是您的secondVIewcontroller.h创建一个NSString就像

 @interface SignUpViewController : BaseViewController<UITextFieldDelegate, UIAlertViewDelegate>{

}
 @property (retain, nonatomic) NSString *strFromUnlinkPage;

 @property (retain, nonatomic) IBOutlet UILabel *lblGuide;   //assumethat this is your secondviewcontroller `UIlabel` Name

在您的 .m ViewDidLoad

- (void)viewDidLoad
{
[super viewDidLoad];
self.lblGuide.text=[NSString stringWithFormat:@"%@", strFromUnlinkPage];
}

这篇关于在iOS中将两个文本字段添加/串联到一个标签中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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