0
これは私のメインウィンドウに2つの異なるカスタムビューを読み込むことができるコードです。私の質問は、PageOneから現在のビューを削除し、新しいもの "text1Title2"で置き換えるように求める、私のPageTwoメソッドを呼び出すボタンを押したときです。問題は、コードを再構築して1つのメソッド内に配置しないと、スイッチのステートメントが必要になるため、これを行う方法がわかりません。 PageTwoメソッドが呼び出されたときに、他のメソッドからビューを削除するか、そのメソッドを解放する方法はありますか?別の方法からビューを削除する方法
- (void) PageOne
{
NSLog(@"FirstPart");
WelcomeScreenText1* text1ViewController =
[[WelcomeScreenText1 alloc] initWithNibName:text1Title bundle:nil];
if (text1ViewController != nil)
{
myCurrentViewController = text1ViewController;
}
// embed the current view to our host view
[myTargetView addSubview: [myCurrentViewController view]];
// make sure we automatically resize the controller's view to the current window size
[[myCurrentViewController view] setFrame: [myTargetView bounds]];
}
- (void) PageTwo
{
if ([myCurrentViewController view] != nil)
[[myCurrentViewController view] removeFromSuperview]; // remove the current view
if (myCurrentViewController != nil)
[myCurrentViewController release];
WelcomeScreenText2* text2ViewController =
[[WelcomeScreenText2 alloc] initWithNibName:text1Title2 bundle:nil];
if (text2ViewController != nil)
{
myCurrentViewController = text2ViewController;
}
// embed the current view to our host view
[myTargetView addSubview: [myCurrentViewController view]];
// make sure we automatically resize the controller's view to the current window size
[[myCurrentViewController view] setFrame: [myTargetView bounds]];
}