0

電話を振って新しいビューを開くアプリケーションを作成しました。全部で 3 つのビューがあり、最後のビューで電話を振ると最初の画面に戻ります。独自の .xib を使用して新しいサブクラス コントロール ビューを作成している場合、これは正常に機能します。しかし、これをストーリーボード プロジェクトで使用したいのですが、何を変更する必要がありますか?

事前にどうもありがとう!

.H のコードは次のとおりです。

#import <UIKit/UIKit.h>
#import "FirstScreenViewController.h"
#import "SecondScreenViewController.h"

@interface ViewController : UIViewController

{

NSInteger currentScreen;
UIViewController* currentController;

}

@終わり

そして、ここで .M:

#import "ViewController.h"

@実装ViewController

-(無効)didReceiveMemoryWarning

{

[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.

}

#pragma mark shake

-(BOOL)ファーストレスポンダーになることができます

{

return true;

}

-(void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)イベント

{

if(motion == UIEventSubtypeMotionShake)

{

if (現在のコントローラー)

{

[currentController.view removeFromSuperview]; currentController=nil;

    }

    switch (currentScreen)

{

        case 0:
            currentController = [[FirstScreenViewController alloc] initWithNibName:@"FirstScreenViewController" bundle:nil];
            break;
        case 1:
            currentController = [[SecondScreenViewController alloc] initWithNibName:@"SecondScreenViewController" bundle:nil];

    }


    if(currentController)

{

        [currentController.view setFrame:self.view.bounds];
        [self.view addSubview:currentController.view];

    }

    currentScreen++;
    if(currentScreen >2)
        currentScreen=0;

}

}

#pragma mark - View lifecycle

-(void)viewDidLoad

{

[super viewDidLoad]; 現在のスクリーン = 0;

}

-(void)viewDidUnload

{

[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;

}

@終わり

4

1 に答える 1

1

3 つのビュー コントローラーすべてをストーリーボードに追加し、それらの間にセグエ (3 番目から 1 番目に戻るものを含む) と、各シーンに接続されたシェイク ジェスチャ レコグナイザーを用意する必要があります。

各ジェスチャ レコグナイザのアクション メソッドはperformSegue:、適切なセグエ識別子を使用してビュー コントローラに指示します。

于 2012-02-16T07:18:16.600 に答える