I have classes Compose and Haiku, each connected to a view controller in IB. Haiku is instantiated in Compose as ghhaiku. Haiku has an array, self.arrayOfHaiku, with 117 members. But in Compose, self.ghhaiku.arrayOfHaiku has no members.
I think the problem is that I haven’t linked the instance of Haiku that has the 117-member array with the instance of Haiku created in Compose. But how do I do that?
(I could of course be totally wrong and the problem could be something else, but that seems to make intuitive sense.)
Any thoughts?
EDIT:
Haiku.m contains the following code:
-(void)viewDidLoad
{
[super viewDidLoad];
[self.arrayOfHaiku addObjectsFromArray:userH];
NSLog(@"%d",self.arrayOfHaiku.count); //This logs 117.
[self goToNextHaiku];
}
Compose.h contains the line @property (strong, nonatomic) Haiku *ghhaiku;
Compose.m contains the following code:
@synthesize ghhaiku;
- (void)viewDidLoad
{
[super viewDidLoad];
//Lots of other code
NSLog(@"%d",self.ghhaiku.arrayOfHaiku.count); //this logs 0.
}
Ok you are never initializing the ghaiku, just defining it. Also why is haiku have a viewDidLoad method? Basically you need to do something like:
in your Compose.m
Just an fyi, if
Haikuis just a model class you shouldn’t use it as a view/viewcontroller. Just as an NSObject. Then just do:just remember to define the method in your
Haiku.hREAD THIS FIRST
Ok I originally misunderstood what you were doing but I think you should still make a
Haikussingleton class (i will update the above code to reflect that later when I have more time — or you can google) then just call[Haikus sharedInstance].arrayOfHaikusin each of your view controllers.