导航栏隐藏在内容后面

时间:2012-07-02 14:19:33

标签: iphone objective-c ios uiviewcontroller uinavigationcontroller

这是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];

2 个答案:

答案 0 :(得分:1)

大多数情况下,您不会继承UINavigationController。相反,您创建UIViewControllers的子类,然后使用普通的UINavigationController实例来处理视图控制器。

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

在XCode中查看导航控制器模板。

答案 1 :(得分:0)

不要继承UINavigationController!

  

UINavigationController类实现了一个专门的视图控制器,用于管理分层内容的导航。 此类不适用于子类化。相反,在希望应用程序的用户界面反映内容的层次结构特性的情况下,可以按原样使用它的实例。此导航界面可以有效地呈现您的数据,并使用户更容易浏览该内容。

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

相关问题