Register2ViewController

Register2ViewController

本文介绍了IOS Objective C - 在两个视图控制器之间传递参数时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个视图控制器:

注册ViewController &注册2视图控制器

RegisterViewController & Register2ViewController

我有一个从RegisterViewController 到Register2ViewController 的segue.

I have a segue from RegisterViewController to Register2ViewController.

我想将 Register2ViewController 中 textfielduser 的值设置为用户在 RegisterViewController 中的 textfieldemail 中输入的值.

I want to set the value of a the textfielduser in Register2ViewController with a value that the user entered in a the textfieldemail in RegisterViewController.

到目前为止,这是我所做的.

so far here is what i've done.

RegisterViewController.m

- (IBAction)NextPage:(UIButton *)sender {

    [self performSegueWithIdentifier:@"toRegister2" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{


    if ([[segue identifier] isEqualToString:@"toRegister2"]) {
        Register2ViewController *controller = (Register2ViewController *)segue.destinationViewController;
        controller.user.text = self.email.text;
    }

但是当我运行并在 RegisterViewController 中填充文本字段的值并转到 Register2ViewController 时,文本字段用户为空,您能帮我吗?谢谢

but when I run and fill the values of textfields in RegisterViewController and go over to Register2ViewController the textfield user is empty, can you help me please? Thank you

推荐答案

不要直接将值传递给 textField,而是尝试使用 NSString 传递文本.在 Register2ViewController 中声明 @property (strong,nonatomic) NSString *userName;.然后将值传递给字符串,如

Instead of directly passing value to textField, try passing text using NSString. Declare @property (strong,nonatomic) NSString *userName; in Register2ViewController. Then pass value to string like

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"toRegister2"]) {
        Register2ViewController *controller = (Register2ViewController *)segue.destinationViewController;
        controller.useName= self.email.text;
    }

然后在 Register2ViewControllerviewDidLoad 中,像这样 self.user.text=self.userName 在 textField 上设置字符串.尝试这样做.

Then in viewDidLoad of Register2ViewController ,set string on textField like this self.user.text=self.userName. Try doing this.

这篇关于IOS Objective C - 在两个视图控制器之间传递参数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-21 01:39