I have 3 view controllers A,B,C .. I want to pass data from A to C... I know i have to create a property in C and use it in A.
But I dont know why.. after setting the value in A i still get a null value in the view C..
As per given suggestions i have created a new project and a new code... What i want to achieve is simple from view A i want a value to be passed in view C..but currently it is giving null..
My view 1.h file...
@interface ViewController : UIViewController
- (IBAction)ActionButton:(id)sender;
@end
view 1.m file..
#import "ViewController.h"
#import "ViewController3.h"
#import "ViewController2.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)ActionButton:(id)sender {
ViewController3 *v3 = [[ViewController3 alloc]init];
v3.string = @"String";
// [self.view addSubview:v3.view];
ViewController2 *v2 = [[ViewController2 alloc]initWithNibName:@"ViewController2" bundle:nil ];
[self.view addSubview:v2.view];
}
@end
View 2.h file...
@interface ViewController2 : UIViewController
- (IBAction)ActionButton:(id)sender;
@property (nonatomic,retain) NSString *string1;
@end
View 2.m file
#import "ViewController2.h"
#import "ViewController3.h"
@interface ViewController2 ()
@end
@implementation ViewController2
- (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)ActionButton:(id)sender {
ViewController3 *v3 = [[ViewController3 alloc]initWithNibName:@"ViewController3" bundle:nil ];
[self.view addSubview:v3.view];
}
@end
View 3.h file..
@interface ViewController3 : UIViewController
@property(nonatomic,retain) NSString *string;
@end
And View 3.m file...
#import "ViewController3.h"
@interface ViewController3 ()
@end
@implementation ViewController3
@synthesize string;
- (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.
NSLog(@"%@",string);
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
FYI if i remove the commented code in view1 i get the value in view 3, but this changes my sequence which i don't want...