Adding/Concatenating two textfields into one label in iOS

后端 未结 2 444
猫巷女王i
猫巷女王i 2021-01-27 09:12

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?

相关标签:
2条回答
  • 2021-01-27 09:48

    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
    0 讨论(0)
  • 2021-01-27 09:51

    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];
    }
    
    0 讨论(0)
提交回复
热议问题