Passing a NSString to another ViewController using classes
- by Jeff Kranenburg
I know this insanely simple, but I am re-teaching myself the basics and trying to get my head around this:-)
I have one ViewController called MainVC and I have one called ClassVC
In ClassVC I have this code:
@interface ClassVC : UIViewController
{
NSString *mainLine;
}
@property (nonatomic, retain) NSString *mainLine;
@end
and I have this in the implementation file:
@synthesize mainLine = _mainLine;
-(NSString *)_mainLine
{
_mainLine = @"This a string from a Class";
return _mainLine;
}
Now I was thinking that if I #import the ClassVC into MainVC I would be able to transfer that string along as well like so:
This code is in the viewDidLoad
_mainLabel.text = _secondClass.mainLine;
NSLog(@"%@", _secondClass.mainLine);
But that is not working - so cannot I not pass strings in through this way???