Passing a NSString to another ViewController using classes
        Posted  
        
            by 
                Jeff Kranenburg
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Jeff Kranenburg
        
        
        
        Published on 2012-09-06T00:37:04Z
        Indexed on 
            2012/09/06
            21:38 UTC
        
        
        Read the original article
        Hit count: 219
        
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???
© Stack Overflow or respective owner