0

私は2 UIViewControllerを持っていて、UINavigationBarをUINavigationBar & UINavigationItemに入れたいと思っています。しかし、私のコードはここ..2 UIViewControllerのためのUINavigationControllerを作成

を働いていない私のコードです:

#import "testView1.h" 
#import "testView2.h" 

@interface testView1() 

@end 

@implementation testView1 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 
    self.view.backgroundColor = [UIColor darkGrayColor]; 
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:self]; 
    testView2 *detail = [testView2 new]; 
    [navController pushViewController:detail animated:YES]; 
} 
+0

以下のように、あなたは、ストーリーボードを使用していますか? – Subramanian

+0

実際にあなたがここでやっているのは、ウィンドウにすでに存在しているrootviewコントローラを持つナビゲーションコントローラをallocして初期化するだけだということです。このステップは、適切な結果のために、AppDelegateで行うべきではありません –

+0

@Subramanianいいえ私はストーリーボードでUIViewControllerを作成し、それをtestView1に設定します –

答えて

1

試してみてください。

まずストーリーボードであなたのtestView1を選択します。

を選択し、ナビゲーションコントローラ

enter image description here

と変更

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view. 

    /// testView2 *detail = [testView2 new]; 
    testView2 *detail = [self.storyboard instantiateViewControllerWithIdentifier:@"testView2 Identifier"]; // if you have add controller in storyboard 
    [self.navigationController pushViewController:detail animated:YES]; 
} 
+0

です。 –

+0

@SaMiGiMiXようこそ、あなたを助けることへの私の喜び。 – KKRocks

+0

tnx。しかし、私はナビゲーションバーにナビゲーションバーを追加することはできません –

0

すでにナビゲーションコントローラ上に第2のビューコントローラをプッシュするので、あなたが最初のビューコントローラは表示されません。以下のようにストーリーボードにナビゲーションコントローラを埋め込む

+0

いいえ、私の最初のViewController ColorはdarkGrayです。そして、画面を実行した後、darkGray .. –

関連する問題