2010-04-27 74 views
0

我需要一些幫助來查找層次結構中的視圖。iPhone - 如何查找父級視圖

以下是我如何構建View堆棧。

裏面我第一次的UITableViewController我推包含一個的UITabBarController一個的UIViewController:

[[self navigationController] pushViewController:itemVC animated:YES]; 

中的UITabBarController我在裏面添加的UITableViewController:

ISSTableViewController *graphics = (ISSTableViewController *)[tabBarController.viewControllers objectAtIndex:3]; 

的didSelectRowAtIndexPath方法裏面我提出用模態視圖控制器UINavigationController:

GraficoViewController *graph = [[GraficoViewController alloc] initWithNibName:@"GraficoViewController" bundle:nil]; 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:graph]; 
    [self presentModalViewController:navigationController animated:YES];  
    [navigationController release]; 

現在(BIG)的問題是: 我必須在我的最後一個視圖中隱藏我的第一個UITableViewController的NagivationBar。 我試着用這樣的:

[[[[[self parentViewController] parentViewController] parentViewController] navigationController] setNavigationBarHidden:YES]; 

,但它不工作。 有人可以告訴我如何找到我的祖先視圖? 謝謝。

回答

1

將指針(作爲屬性)存儲到應用程序委託或自定義單例對象中的UINavigationController。然後,您可以從任何地方訪問您的導航。

+0

我想過,但我正在尋找一個更乾淨的解決方案。 – 2010-04-27 11:18:07

+0

這是一個很好的解決方案,因爲如果您要更改控制器層次結構,那麼這將是無需更改的工作。 – Skie 2010-04-27 13:27:19