Just defining and declaring the two strings is not enough. That makes sure that each class has a variable called string or string2 - but when your program is running, it is actual objects that must refer to specific instances of string1 (or string2).
It's like designing a house with a letterbox - the letterbox is there on the plan of the house, but nothing happens until a specific letter gets sent to a specific house.
What you need to do is wire up the actual instances of your class, possibily in an init method, like this:
// 1.h
@interface ViewController1 : UIViewController
{
// declare our variable
NSString* string1;
}
// declare 'string1' as a property
@property (retain) NSString* string1;
// 1.m
// implements the property for string1
@synthesize string1;
// 2.h
@interface ViewController2 : UIViewController
{
// declare our variable
NSString* string2;
}
// declare 'string2' as a property
@property (retain) NSString* string2;
// 2.m
- (id)initWithTitle:(NSString*)aTitle andString1:aString
{
if (self = [super init])
{
self.title = aTitle;
self.string1 = aString;
}
return self;
}
Then in 1.m, you create the second controller, and wire the strings up, like this:
// 1.m
mySecondController = [[ViewController2 alloc] initWithTitle:@"Controller 2" andString:string1];