2

1 つのアプリを作成したいのですが、フォームの送信が含まれています。この中で私は単一のビュー アプリケーションによって 1 つの新しいプロジェクトを作成します。この firstViewController にボタンを配置し、それを押すと、secondViewController にリダイレクトされます。

これで私はフォームを持っています。ユーザーからデータを取得し、送信ボタンを使用して、これを thirdViewController にリダイレクトし、フォーム データを thirdViewController に出力したいと考えています。

私が書いたfirstViewController.mファイルに

-(IBAction)nextVCButton:(id)sender
{

SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

NSLog(@"name : %@",self.nameTextField.text);
tempView.fullName = self.nameTextField.text;
[tempView setFullName:self.fullName];
[self.view addSubview:tempView.view];

}

SecondViewController.m ファイル内

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

NSLog(@"received info %@", [self.fullName description]);

self.nameLabel.text = [self.fullName description];

}

ログでは (name :) 値を取得していますが、secondViewController で受信した情報は null です。

私は xib ファイルを使用してこれをすべて行っています。ストーリーボードは使用しません。

このフォームデータを secondViewController に取得するのを手伝ってください。

ありがとう。

4

3 に答える 3

2

申し訳ありませんが、なぜこれらの 2 行のコードを実行したのかわかりませんでした:

tempView.fullName = self.nameTextField.text;
[tempView setFullName:self.fullName];

NSString代わりに、 Second View Controller のプロパティを作成します.h file

@property (nonatomic,retain)    NSString *strFullName;

で合成し.m fileます。

@synthesize strFullName;

今 、

-(IBAction)nextVCButton:(id)sender
{

SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

NSLog(@"name : %@",self.nameTextField.text);
tempView.strFullName = self.nameTextField.text;
[self.view addSubview:tempView.view];
}
于 2013-06-17T05:49:56.097 に答える
1

Navigation controllerあるView Controllerから別のView Controllerに移動する場合は、使用する必要があると思います。ここで、プロパティを実行する必要があります- で iVar "fullName" を合成しますThirdViewController。の値を保持しますSecondViewController

1.ThirdViewController.h

 @property(nonatomic, retain) NSString *fullName;

2.ThirdViewController.m

@synthisize fullName;
dealloc {
[fullName release];
}

3.SecondViewController.m

-(IBAction)nextVCButton:(id)sender
{

SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

NSLog(@"name : %@",self.nameTextField.text);
tempView.fullName = self.nameTextField.text; 
[tempView setFullName:self.fullName];
[self.view addSubview:tempView.view];
}
于 2013-06-17T05:50:16.730 に答える
0

addSubview...の代わりに presentViewController メソッドを試してください。

-(IBAction)nextVCButton:(id)sender
{
    SecondViewController *tempView = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];

    NSLog(@"name : %@",self.nameTextField.text);
    tempView.strFullName = self.nameTextField.text;
    [self.view addSubview:tempView.view];
    [self presentViewController:tempView animated:YES completion:nil];
}
于 2013-06-17T05:58:33.487 に答える