2

私のプロジェクトの現在のバージョン:

UIViewControllers私のアプリには5つの異なるものがあります。属性インスペクターを使用FirstViewControllerするように設定 しました。Initial View ControllerStoryBoardを使用して、あるViewControllerから別のViewControllerにモーダルセグエを割り当てるボタンを使用して、あるViewControllerから別のViewControllerに移動します。

変更したいこと:

UINavigationControllerナビゲーションボタンを明らかに残し、モーダルセグエを削除して代わりに使用したいと思います。概念を正しく理解している場合、を使用するときは、UINavigationControllerそれぞれに移動する必要が UIButton-IBActionあり、メソッドの最後で、移動する次のViewControllerをNavigationControllerにプッシュする必要があります(現在のViewControllerもポップする必要がありますか?最初?)。しかし、それを正しく実装する方法がわかりません。

私がこれまでにしたこと:

  • ストーリーボードからすべてのモーダルセグエを削除し、ナビゲーションボタンとそれに対応するIBActionを保持しました
  • FirstViewControllerをアプリの最初のViewControllerにする属性インスペクターのチェックボックスをオフにしました
  • AppDelegate.mにアクセスし、そこでナビゲーションコントローラーを作成して、 FirstViewControllerをRootViewControllerにしようとしました。

MyAppDelegate.m

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIViewController *myFirstViewController = [[FirstViewController alloc] init];
    UINavigationController *myNavigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController];

    [myNavigationController pushViewController:myFirstViewController animated:YES];

    // Override point for customization after application launch.

    return YES;
}
  • 次に、FirstViewControllerのナビゲーションボタンのIBActionに移動して上記が機能するかどうかをテストし、ボタンが押されたときにSecondViewControllerに移動するために以下を実装しました。

FirstViewController.m

- (IBAction)goRightButton:(UIButton *)sender
{
    // some code drawing the ButtonIsPressed UIImageView on the current View Controller

    UIViewController *mySecondViewController = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:mySecondViewController animated:YES];
}

しかし、何も起こりません。私は何を間違っているのですか?

4

2 に答える 2

2

XIB ファイルをリンクしていません。ナビゲーションコントローラーを次のように追加してください

UIViewController *myFirstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];
navigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController];

次のコードを使用して、あるビューから別のビューに移動します

UIViewController *mySecondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
[self.navigationController pushViewController:mySecondViewController animated:YES];
于 2012-09-05T12:44:31.563 に答える
0

ストーリーボードを使用している場合は、そこにナビゲーション コントローラーをドラッグして、アプリ デリゲートに接続するだけです。それがメインのストーリーボードであり、最初に読み込むビュー コントローラーを特定している限り、アプリ デリゲートにビューを読み込む必要はありません。

ストーリーボードにあるビューをプログラムでプッシュするには、次のようにする必要があります。

 //bundle can be nil if in main bundle, which is default
 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
 MyCustomViewController *customVC = (MyCustomViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"customVC"];
//standard way
[self.navigationController pushViewController:customVC animated:YES];

//custom animation
[UIView transitionWithView:self.navigationController.view duration:0.5 options:UIViewAnimationOptionTransitionCurlUp animations:^{
    [self.navigationController pushViewController:customVC animated:NO];
} completion:nil];

ストーリーボード エディターで追加した識別子でビュー コントローラーを識別します。以下は、私が何を意味するかを示すのに役立つスクリーンショットです。

初期ロードを示す矢印付きのナビゲーション コントローラー

ビューコントローラーの識別子を変更する場所で、それを呼び出すことができます

于 2012-09-05T13:31:14.503 に答える