iPhoneのサンプルを見ていますプログラミングの本の初めに、ボタンを押したときに2つのビューを切り替えるコードがあります。objective-cのsuperviewを削除する
if (self.yellowViewController.view.superview == nil)
{
if (self.yellowViewController == nil)
{
YellowViewController *yellowController =
[[YellowViewController alloc] initWithNibName:@"YellowView"
bundle:nil];
self.yellowViewController = yellowController;
[yellowController release];
}
[blueViewController.view removeFromSuperview];
[self.view insertSubview:yellowViewController.view atIndex:0];
}
else
{
if (self.blueViewController == nil)
{
BlueViewController *blueController =
[[BlueViewController alloc] initWithNibName:@"BlueView"
bundle:nil];
self.blueViewController = blueController;
[blueController release];
}
[yellowViewController.view removeFromSuperview];
[self.view insertSubview:blueViewController.view atIndex:0];
}
それは私には意味をなさないんが、私が持っている問題は、あなたが4つのビューを持っているUISegmentControlでこれを行うだろうか、次のとおりです。ここでは、そのサンプルコードから最初の抜粋です。私はあなたがselectedSegmentを確認し、必要に応じてそのビューを作成できることを知っています。しかし、私の新しいビューをサブビューとして追加するのを助けるために、スーパービューからそれを削除するために最後のビューがどのようなものか分かりましたか?ありがとう!
適切なインデントを行うと、このコードを読みやすくなります。 –