4

UINavigationController があり、UISegmentControl を使用して切り替える個別の UIView があります。ビューを切り替えるときに、ビューをサブビューとしてナビゲーション コントローラーのビューに追加します。

[self.view addSubview:segmentTab1.view];

[self.view addSubview:segmentTab2.view];

次に、サブビューにはそれぞれUITableViewがありますが、私の問題は、didSelectRowAtIndexPathメソッドで新しいviewControllerをビューにプッシュできないことです。

メソッドは正しく呼び出され、ブレークポイントを設定することで、ビューをプッシュするメソッドも呼び出されることがわかりますが、何も起こりません。これはそれをプッシュするための私のコードです:

[self.navigationController pushViewController:detailsViewController animated:YES];

私も試しました

[super.navigationController pushViewController:detailsViewController animated:YES];

私は何を間違っていますか?またはサブビューでそれを行うことはできませんか?

4

6 に答える 6

6

When you call -pushViewController, which view controller is self? If you are calling that from within one of your tab subviews, self likely doesn't have a reference to the navigation controller from the top level view that you added it to. You can verify this by getting the memory address of the navigation controller from within the top level view and comparing it to what you have in the subview. Obviously if it's nil or doesn't match, then that's your problem.

You only get a navigation controller "for free" when it's been added to the navigation stack itself with -pushViewController which your subviews haven't been added that way.

于 2009-11-06T17:35:46.657 に答える
2

すべてのビューに共通のヘッダーを実装するときに同様の問題がありました多くの試行の後、これで修正しました-

すべてのviewControllerで

- (void)viewWillAppear:(BOOL)animated {

    [self.view addSubview:[[(NavAppAppDelegate *)[[UIApplication sharedApplication] delegate] headerview] view]];
    [[(NavAppAppDelegate *)[[UIApplication sharedApplication] delegate] headerview] viewWillAppear:YES];

}

iPhone の複数のビュー コントローラーでヘッダー ビュー Common XIBを実装するには、次の投稿を参照しました。

[self.view addSubview:[[(NavAppAppDelegate *)[[UIApplication sharedApplication] delegate] headerview] view]];     // line will load the header subview 

[[(NavAppAppDelegate *)[[UIApplication sharedApplication] デリゲート] headerview] viewWillAppear:YES]; // これは、HeaderController の viewWillAppear メソッドを呼び出して、ユーザーがログに記録されているかどうかを確認するコードを記述し、ログイン ボタンをログアウト ボタンに変更するなど..

于 2012-11-03T17:13:08.480 に答える
1

それ以外の

[self.view addSubview:segmentTab1.view];

[self.view addSubview:segmentTab2.view];

あなたが使用することができます

[self pushViewController: segmentTab1 animated: NO];

[self pushViewController: segmentTab2 animated: NO];

viewControllersをナビゲーション階層に追加し、機能させます[super.navigationController pushViewController:detailsViewController animated:YES];

于 2009-11-06T17:59:41.757 に答える
0
LogEntryDetailViewController *leController = [[LogEntryDetailViewController alloc] initWithNibName:@"LogEntryDetailView" bundle:[NSBundle mainBundle]];
    [leController setTitle:[NSString stringWithFormat:@"%@", [logEntriesArray objectAtIndex:row]]];
    [[self navigationController] pushViewController:leController animated:NO];      
    [leController release], leController = nil;
于 2010-11-25T02:17:06.097 に答える
0

ビュー階層が何であるかは完全にはわかりませんが、一般に、ナビゲーション コントローラー ビューがウィンドウの最初のサブビューまたは Apple のコレクション ビュー (別のナビゲーション ビュー コントローラーのコンテンツ ビューまたはタブ コントローラーのいずれか) の要素ではない場合コンテンツ ビュー) では正しく動作しません。

于 2009-11-06T17:45:28.163 に答える
0

シングルトンが嫌いでない場合、1 つの可能性は、製品の UINavigationController オブジェクトをシングルトンにして、(たとえば) アプリケーション デリゲートからアクセスできるようにすることです。

次のように呼び出します。

[[((MyApplicationDelegate*)[UIApplication delegate]) navController] 
                pushViewController: viewControllerToPush animated: YES];

MyApplicationDelegate 内で、navController はシングルトン オブジェクトを返します。

于 2009-11-06T18:31:32.203 に答える