Adding/Concatenating two textfields into one label in iOS

风流意气都作罢 提交于 2019-12-31 06:10:15

问题


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?


回答1:


assume that this is your first Viewcontroller

this is your UIButton action for Navigating 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];

}

this is your secondVIewcontroller.h create the one NSString just like

 @interface SignUpViewController : BaseViewController<UITextFieldDelegate, UIAlertViewDelegate>{

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

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

in your .m ViewDidLoad

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



回答2:


To send data from one page to another have a look SO answer here And to Adding/Concatenating two string you have two ways -

  1. Use NSMutableString that has appendString method.
  2. Save nsstring in NSArray and use componentsJoinedByString Method


来源:https://stackoverflow.com/questions/26686405/adding-concatenating-two-textfields-into-one-label-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!