ViewController間のデータのやりとりの第二弾。
SecondViewController から ViewControllerにデータを渡します。
さっきと逆です!
*********************************************
ViewController.h
@property(nonatomic,retain) NSString *testStr;
*********************************************
ViewController.m
@synthesize testStr;
-(void)pushBtn1 {
// SecondViewControllerを生成
SecondViewController *vc = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
vc.parentVC = self;
// ナビゲーションによる画面遷移を実行
[self.navigationController pushViewController:vc animated:YES];
[vc release];
}
*********************************************
SecondViewController.h
//@interface ViewController2 : UIViewControllerの上に書いてください
@class ViewController;
@property (nonatomic,retain) ViewController *parentVC;
*********************************************
SecondViewController.m
#import "ViewController.h"
@synthesize parentVC = _parentVC;
-(void)goBack {
//SecondViewから値を戻す
self.parentVC.testStr = @"test";
[self.navigationController popViewControllerAnimated:YES];
}
*********************************************
さっきよりずっと複雑です。
自分も何度か見直しながらやっています。