これは私の最初のView Controllerで、xibファイルがあります
.h
#import "SecondViewController.h"
@interface ViewController : UIViewController
@property(strong, nonatomic) SecondViewController * svc;
@end
2番目はxibなしです。
.h
#import <UIKit/UIKit.h>
@class ViewController;
@interface SecondViewController : UIViewController
@property (strong, nonatomic) ViewController * vc;
@property (strong, nonatomic) NSMutableString * passValue;
@end
実装中
最初の.mはviewDidLoadです
- (void)viewDidLoad
{
NSLog(@"viewDidLoad");
[super viewDidLoad];
svc=[[SecondViewController alloc] init];
svc.vc=self;
NSString * str= svc.passValue;
NSLog(@"%@",str);
svc.passValue =[@"StringFromFirstView" mutableCopy];
[svc viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
そして秒で.m
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
passValue = @"mySValue";
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSLog(@"passValue %@",passValue);
// Do any additional setup after loading the view.
}
そして、コードを実行すると
2013-03-16 13:11:40.178 ali[787:c07] viewDidLoad
2013-03-16 13:11:40.179 ali[787:c07] mySValue
2013-03-16 13:11:40.180 ali[787:c07] passValue StringFromFirstView