From what I see here, your qanda *qanda1
is limited to the viewDidLoad
method. Once that method returns, qanda1
no longer exists.
In your view controller's header file, declare a property for qanda1
.
@class Qanda;
@interface MyViewController : UIViewController
.
.
.
@property Qanda *qanda1;
@end
In the implementation file "MyViewController.m):
#import "Qanda.h"
@implementation MyViewController
.
.
.
-(void)viewDidLoad {
Qanda *qanda1 = [[Qanda alloc] init];
qanda1.quote = @"All our dreams can come true – if we have the courage to pursue them. ";
qanda1.author = @"Walt Disney";
}
.
.
.
@end
This way, you have access to qanda1
throughout the lifetime of MyViewController
. You can now perform your self.quote.text = qanda1.quote;
anytime after viewDidLoad
has been called.
I would recommend on reading up on variable scope (here is a good starting point on SO) so that you get complete understanding of what is happening here.
UPDATE
As mentioned in comments to your question, following some basic naming conventions might help to distinguish between instance variables and class names. (for Objective C, but most languages follow the same, if not similar patterns).
Following the usual conventions, your "qanda" class would look like this:
@interface Qanda : NSObject
@property (nonatomic, copy) NSString *quote;
@property (nonatomic, copy) NSString *author;
@end