イメージはこんな感じ。
1.トップ画面

↓ 「受け渡し」ボタンを押下
2.ビューを移動した後の画面

テキストフィールドで「Test」と入力した値が、次のビューのラベル部分に表示される。
下記が実際のコード。
主要部分だけを説明していく。赤字の部分がポイント箇所。
まずは、画像「1,トップ画面」のコード。
◎FirstViewController.h
#import <UIKit/UIKit.h>
#import "SecondViewController.h"
@interface FirstViewController : UIViewController {
// テキストフィールド
UITextField *tf;
}
@end
◎FirstViewController.m
#import "FirstViewController.h"
@implementation FirstViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// テキストフィールド追加
tf = [[[UITextField alloc] initWithFrame:CGRectMake(60, 100, 200, 30)] autorelease];
tf.borderStyle = UITextBorderStyleRoundedRect;
tf.textColor = [UIColor blackColor];
[self.view addSubview:tf];
// ボタンを追加
UIButton *bt = [UIButton buttonWithType:UIButtonTypeRoundedRect];
bt.frame = CGRectMake(110, 150, 100, 30);
[bt setTitle:@"受け渡し" forState:UIControlStateNormal];
[bt addTarget:self action:@selector(buttonAction:)forControlEvents:UIControlEventTouchDown];
[self.view addSubview:bt];
}
-(void)buttonAction:(UIButton*)button
{
// 値を異なるビューへ渡す
SecondViewController *secondViewController = [[SecondViewController alloc] init];
[secondViewController setSvStr:tf.text];
// 画面遷移
[self.navigationController pushViewController:secondViewController animated:YES];
}
@end
次に、画像「2,ビューを移動した後の画面」のコード。
◎SecondViewController.h
#import <UIKit/UIKit.h>
@interface SecondViewController : UIViewController {
}
@property (nonatomic,copy) NSString *svStr;
@end
◎SecondViewController.m
#import "SecondViewController.h"
@implementation SecondViewController
@synthesize svStr;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
// ラベルを追加
UILabel *lb = [[UILabel alloc] init];
lb.frame = CGRectMake(60, 100, 200, 30);
lb.backgroundColor = [UIColor colorWithRed:0.0 green:0.3 blue:0.0 alpha:0.3];
lb.textColor = [UIColor blackColor];
lb.font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
lb.textAlignment = UITextAlignmentCenter;
lb.text = svStr; // 受け取ったFirstViewControllerの値を表示
[self.view addSubview:lb];
}
@end
----------
サンプルソース:https://github.com/tetsuco/ValueGetSet