2011-06-24 13 views
0

これはObjective-Cに関連する質問ですので、明らかに多くのコードとサブクラスがあります。だからここに私の問題です。今、ボタンと2つのカラーUIViewをプログラムで作成するiPadアプリがあります。これらのカラーのUIViewはSubViewControllerによって制御され、全体がMainViewControllerによって制御されるUIViewにあります。 (すなわちMainViewController = [UIButton、SubViewController、SubViewController])Single Subview用ModalViewController

さて、このすべては、それが必要として起こる、と私は(下記)を期待するもので終わる:

viewtools

しかし、ボタンをクリックすると、コンソールに「flipSubView1」と表示されますが、何も起こりません。モーダルビューは表示されず、エラーも発生しません。ただ何も。私が期待するのは、subView1またはビュー全体が水平に反転してsubView3を表示することです。私が見落としているいくつかのバグはあるのでしょうか?

viewtoolsAppDelegate.m

@implementation viewtoolsAppDelegate 

@synthesize window = _window; 
@synthesize mvc; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    // Override point for customization after application launch. 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    mvc = [[MainViewController alloc] initWithFrame:self.window.frame]; 
    [self.window addSubview:mvc.theView]; 
    [self.window makeKeyAndVisible]; 

    return YES; 
} 

MainViewController.m

@implementation MainViewController 

@synthesize theView; 
@synthesize subView1, subView2, subView3; 

- (id)initWithFrame:(CGRect) frame 
{ 
    theView = [[UIView alloc] initWithFrame:frame]; 
    CGRect sV1Rect = CGRectMake(frame.origin.x+44, frame.origin.y, frame.size.width-44, frame.size.height/2); 
    CGRect sV2Rect = CGRectMake(frame.origin.x+44, frame.origin.y+frame.size.height/2, frame.size.width-44, frame.size.height/2); 
    subView1 = [[SubViewController alloc] initWithFrame:sV1Rect andColor:[UIColor blueColor]]; 
    subView2 = [[SubViewController alloc] initWithFrame:sV2Rect andColor:[UIColor greenColor]]; 
    subView3 = [[SubViewController alloc] initWithFrame:sV1Rect andColor:[UIColor redColor]]; 
    [theView addSubview:subView1.theView]; 
    [theView addSubview:subView2.theView]; 

    UIButton *aButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
    [aButton addTarget:self action:@selector(flipSubView1:) forControlEvents:(UIControlEvents)UIControlEventTouchDown]; 
    [aButton setFrame:CGRectMake(0, 0, 44, frame.size.height)]; 
    [theView addSubview:aButton]; 

    return self; 
} 

- (void)flipSubView1:(id) sender 
{ 
    NSLog(@"flipSubView1"); 
    [subView3 setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal]; 
    [subView1 presentModalViewController:subView3 animated:YES]; 
} 

SubViewController.m

@implementation SubViewController 

@synthesize theView; 

- (id)initWithFrame:(CGRect)frame andColor:(UIColor *)color 
{ 
    theView = [[UIView alloc] initWithFrame:frame]; 
    theView.backgroundColor = color; 
    return self; 
} 

TLDR:モーダルビューが動作しません。フリップが見えるはずです。しないでください。

+0

ここで、ViewをSubViewControllerのビューに設定していますか? – thomashw

答えて

0

MainViewControllerの 'view'プロパティをどこでも 'theView'に設定しているようには見えません。コントローラビューのデリゲートは、正しく表示されるように表示されているルートビューに接続する必要があります。サブビューコントローラのインプラントでもそれを修正する必要があります。フレームワーククラスがもたらすすべての配管が必要な場合は、予想通りに設定する必要があります。

さらに、サブビューコントローラの1つでpresentModalViewControllerを呼び出しています。 MainViewControllerがモーダルビューを '所有する'ものであるため、[self presentModalViewController:...]を呼び出すように変更してください。

これらの点を修正すると、-presentModalViewControllerが機能することがわかります。

+0

助けてくれたことが助けてくれましたが、私が望むような振る舞いではありませんでした:)私がやったことは、subView2用のサブビューを持つビューコントローラと、subView1用のサブビューを含むサブビューを作成することでした。次に、UIViewAnimationを使用してsubView1をsubView3にフリップさせました。複雑ですが効果的です。とにかくありがとう! –

+0

MainViewControllerから[-transitionFromView:toView:duration:options:completion:]メソッドを使用して、任意のサブビューと他の新しいサブビューをアニメーション化できます(http://developer.apple.com/library/ios/#DOCUMENTATION/ UIKit/Reference/UIView_Class/UIView/UIView.html)を参照してください。既存のサブビューを 'from'パラメータとして渡し、新しいビューを 'to'パラメータとして渡します。 – RyanR