好的,这是我的第一个视图控制器,它有 xib 文件
。H
#import "SecondViewController.h"
@interface ViewController : UIViewController
@property(strong, nonatomic) SecondViewController * svc;
@end
第二个没有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