私のプロジェクトの現在のバージョン:
UIViewControllers
私のアプリには5つの異なるものがあります。属性インスペクターを使用FirstViewController
するように設定 しました。Initial View Controller
StoryBoardを使用して、ある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];
}
しかし、何も起こりません。私は何を間違っているのですか?