クラスGHHaikuには、BOOLプロパティがありますjustComposed。
私にはmySecondViewControllerClass次の方法があります:
- (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`
}
私にはmyFirstViewController次の方法があります:
-(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"];
}
}
BOOLinは1/yessaveUserHaikuを示しています。mySecondViewControllerしかし、のブール値は0/noviewWillAppearを示しています。myFirstViewController
私は何を省略していますか?
編集:
これは私が最終的に達成しようとしていることです:
myFirstViewControllerでインスタンス化GHHaikuしviewDidLoadます。次にarrayOfHaiku、そのインスタンス化を作成し、x個の俳句をロードします。
のメソッドsaveUserHaikuはmySecondViewController、その配列に俳句を追加し、ブール値YESmyFirstViewController`を設定しjustComposed' toます, and then programmatically switches view controllers back to。
に戻ったら、inが。の場合は特定の関数myFirstViewControllerを呼び出します。viewWillAppearjustComposedmySecondViewControllerYES
両方のViewControllerはInterfaceBuilderで作成されました。
2番目の編集: 重要な場合、これはタブ付きのアプリケーションです。 saveUserHaikuタブを変更します。