1

私は一般的にプログラミングに非常に慣れていません。非常にシンプルなアプリを作ろうとしています。

ストーリーボードを使用して、あるビューコントローラーから別のビューコントローラーにデータを渡そうとしています。私の最初の画面にはテキストフィールドとボタンがあり、ボタンを押した後、テキストフィールドに入力したテキストで2番目の画面のラベルを更新したいと考えています。

これが私のコードの一部です:

#import "FirstViewController.h"
#import "SecondViewController.h"

@interface FirstViewController ()

@end

@implementation FirstViewController

@synthesize secondviewData;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{


    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

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

//    SecondViewController *second = [[SecondViewController alloc] initWithNibName:nil bundle:nil];

    self.secondviewData = secondviewData;
    secondviewData.passedValue = input.text;

//    [self presentViewController:second animated:YES completion:nil];

    homeLabel.text = input.text;

}
@end

#import "SecondViewController.h"
#import "FirstViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

@synthesize passedValue;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{



    label.text = passedValue;

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

ここに私のコードへのリンクがあります: http://oberober.com/passingData/

これまでのところ、最初の画面のテキスト フィールドに何を入力しても、2 番目の画面のラベルは空白のままです。

重要な概念が欠けているような気がしますか?私が見ることができるヒントやチュートリアルはありますか?

前もってありがとう、キャスパー

4

1 に答える 1

4

prepareForSegue最初のコントローラーのメソッドを使用してデータを渡します。これは、私のアプリの1つからの例で、車両オブジェクトが2番目のコントローラーに渡されていることを示しています。
CHRBodyViewController2番目のコントローラーのクラスです。

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    CHRBodyViewController *body = [segue destinationViewController];
    body.vehicle = _vehicle;
    body.updated = YES;

}
于 2013-03-09T06:46:19.777 に答える