0

這是UINavigationController的init方法。我想我一定是做錯了。隱藏在內容後面的導航欄

- (id)init 
{ 
self = [super init]; 
if (self) { 

    self.view.backgroundColor = [UIColor blackColor]; 

    self.viewController = [[UIViewController alloc] init]; 

    self.viewControllers = [NSArray arrayWithObject:self.viewController]; 


    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"Done" 
                   style:UIBarButtonItemStylePlain 
                   target:self 
                   action:@selector(done)]; 
    self.viewController.navigationItem.rightBarButtonItem = button; 
    self.navigationBar.barStyle = UIBarStyleBlackTranslucent; 

    self.mediaScrollView = [[MediaScrollView alloc] initWithFrame:self.view.bounds]; 
    self.mediaScrollView.touchDelegate = self; 
    self.mediaScrollView.fullScreenDelegate = self; 
    [self.viewController.view addSubview:self.mediaScrollView]; 


} 
return self; 

}

的mediaScrollView會在我的導航欄的前面。它應該出現在導航欄後面。

這是調用它的方法:

self.mediaVC = [[PDMediaViewController alloc] init]; 
    self.mediaVC.mediaScrollView.manualMedia = YES; 
    self.mediaVC.mediaScrollView.mediaDelegate = self; 
    self.mediaVC.mediaScrollView.currentMediaItem = 0; 

    self.mediaVC.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
    [self presentModalViewController:self.mediaVC animated:YES]; 
+0

不繼承UINavigationController的(除非你真的* *知道你在做什麼!) –

回答

1

你們中的大多數不繼承UINavigationController的時間。相反,您創建UIViewControllers的子類,然後使用正常的UINavigationController實例來處理您的視圖控制器。

MyViewController *firstViewController = [[MyViewController alloc] init]; 
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:firstViewController]; 
[window addSubview:navController.view]; 

查看XCode中的導航控制器模板。

+0

所以在我把它叫做類,我得給它像一個半透明的導航欄屬性每次? – Andrew

+0

是的。或者在視圖控制器的viewWill/DidDisplay方法中。 – DrummerB

0

不要繼承UINavigationController!

UINavigationController類實現了管理分層內容導航的專用視圖控制器。 此課程不適用於子類別。相反,如果您希望應用程序的用戶界面能夠反映內容的層次性,您就可以使用它的實例。此導航界面可以有效地呈現您的數據,並且使用戶可以更輕鬆地瀏覽該內容。

http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html