In the class GHHaiku I have the BOOL property justComposed.
In mySecondViewControllerClass I have the following methods:
- (void)viewDidLoad
{
[super viewDidLoad];
if (!self.ghhaiku)
{
self.ghhaiku = [[GHHaiku alloc] init];
}
//Lots of other code
}
-(void)saveUserHaiku
{
//Lots of code
self.ghhaiku.justComposed=YES;
NSLog(@"%d",self.ghhaiku.justComposed);
[self.tabBarController setSelectedIndex:0]; //This switches to `myFirstViewController`
}
In myFirstViewController I have the following methods:
-(void)viewDidLoad
{
[super viewDidLoad];
if (!self.ghhaiku)
{
self.ghhaiku = [[GHHaiku alloc] init];
}
}
- (void) viewWillAppear:(BOOL)animated
{
NSLog(@"%d",self.ghhaiku.justComposed);
if (self.ghhaiku.justComposedYes==YES)
{
[super viewWillAppear:animated];
self.displayHaikuTextView.text = [[self.ghhaiku.arrayOfHaiku lastObject] valueForKey:@"quote"];
}
}
The BOOL in saveUserHaiku in mySecondViewController shows 1/yes. But the Boolean in viewWillAppear in myFirstViewController shows 0/no.
What am I leaving out?
EDIT:
This is what I’m trying to accomplish in the end:
myFirstViewController instantiates GHHaiku in viewDidLoad. Then it creates arrayOfHaiku on that instantiation and loads it with x number of haiku.
The method saveUserHaiku in mySecondViewController adds a haiku to that array, sets a Boolean justComposed' toYES, and then programmatically switches view controllers back tomyFirstViewController`.
Once we’re back in myFirstViewController, viewWillAppear calls a certain function if justComposed in mySecondViewController is YES.
Both view controllers were created in Interface Builder.
SECOND EDIT: In case it matters, this is a tabbed application. saveUserHaiku changes the tab.
It appears that you are creating separate instances of ghhaiku – one for each of your two view controllers. If you would like to use the same ghhaiku object between both view controllers (thereby remembering the justComposed boolean), you will need to set the ghhaiku property to the existing object when you create the view controller. Do not alloc/init a new one in viewDidLoad.
For instance, if you were to display mySecondViewControllerClass from myFirstViewController, it might look like the following: