vasupradha vasupradha - 5 months ago 8
iOS Question

Adding/Concatenating two textfields into one label in iOS

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?

Answer

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];
}