我試圖從UINavigationController中得到一種「從左到右」的分層導航。我使用此代碼:如何讓UIBarButtonItem調用「pushViewControllerAnimated:(BOOL)」到UINavigationController?
-(IBAction)showSettings:(id)sender {
UINavigationController *aNavController = [[UINavigationController alloc] initWithNibName:nil bundle:nil];
[self presentModalViewController:aNavController animated:YES];
SecondView *secondView = [[SecondView alloc] initWithNibName:nil bundle:nil];
[aNavController pushViewController:secondView animated:NO];
UIBarButtonItem *aButton = [[UIBarButtonItem alloc] initWithTitle:@"Knapp" style:UIBarButtonItemStylePlain target:self action:@selector(nextView:)];
aNavController.topViewController.navigationItem.rightBarButtonItem = aButton;
[aButton release];
[secondView release];
[aNavController release]; }
-(IBAction)nextView:(id)sender {
ThirdView *thirdView = [[ThirdView alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:thirdView animated:YES];
NSLog(@"Push it like it's hot"); }
「新思維」被正確地叫,「推它,喜歡它的熱」,印在「輸出」,但沒有被按下時,沒有新的視圖顯示出來。我也嘗試改變: [self.navigationController pushViewController:thirdView animated:YES];
到[self.navigationController popViewControllerAnimated:YES];
但結果保持不變,沒有任何反應。
我的結論是這樣的:我在'nextView'的self.navigationController部分做了錯誤的事,即程序不知道從/到什麼推/彈出。我已經盡力去查看某種有關這方面的文檔,但是我無法解決,所以我就是這樣。
是self.navigationController做到這一點的正確方法,或者我錯過了該行的內容?
預先感謝您, 託拜厄斯Tovedal
蘇海爾!你絕對正確,'NSLog(@「%@」,self.navigationController);'輸出'(null)'。在頭文件中添加'aNavController'作爲一個變量解決它,謝謝你的幫助! /托比亞斯 –