FlipsideViewController の提示方法に応じて、いくつかの方法があります。
- "background" を FlipsideViewController のプロパティにし、VC を表示する前に各ボタンのアクション メソッドで必要に応じて設定します。
- FlipsideViewController に「background」パラメーターを指定してカスタム init メソッドを追加します。
「背景」は int または列挙型のプロパティ/パラメータである可能性があり、FlipsideViewController のコードは、その値に基づいて必要なことを実行します。
編集:
プロパティアプローチを使用するには:
まず、FlipsideViewController で、say という UIImageView の IBOutlet があることを確認しますbackgroundImageView
。
次に、FlipsideViewController.h で、背景を設定するプロパティを追加します (私は int を使用しています)。
@interface FlipSideViewController : UIViewController {
int backgroundId;
}
@property (assign) int backgroundId;
次に、FlipsideViewController.m に以下を追加します。
@synthesize backgroundId;
-(void)viewWillAppear:(BOOL)animated
{
if (backgroundId == 2)
self.backgroundImageView.image = [UIImage imageNamed:@"background2.png"];
else
self.backgroundImageView.image = [UIImage imageNamed:@"background1.png"];
}
最後に、メイン ビュー コントローラーでは、ボタン アクション メソッドは次のようになります。
-(IBAction)buttonPressed:(UIButton *)sender
{
FlipSideViewController *fsvc = [[FlipSideViewController alloc] initWithNibName:nil bundle:nil];
fsvc.backgroundId = sender.tag; //assuming btn1.tag=1 and bnt2.tag=2
[self presentModalViewController:fsvc animated:YES];
[fsvc release];
}