导航栏不会出现

时间:2014-05-13 15:09:52

标签: ios objective-c uinavigationcontroller uinavigationitem

似乎我做错了什么,但我不明白是什么。我有UIViewController,这是viewDidLoad方法:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.navigationController.navigationBarHidden=NO;

    // tableview initialisation

    // search bar initialisation

   menu = [[SINavigationMenuView alloc] initWithFrame:CGRectMake(-10, 0, 200, self.navigationController.view.frame.size.height) title:NSLocalizedString(@"ALBUMS", nil)];
   [menu displayMenuInView:self.view];
   menu.tableFrame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);


   menu.items = @[NSLocalizedString(@"ALL", nil), NSLocalizedString(@"DOWNLOADS", nil), ...];

   menu.delegate = self.controller;
   self.navigationItem.titleView = menu;

   //sidebar button
   UIImage *sidebarButtonImage = [UIImage imageNamed:@"menu"];
   UIButton * sidebarButton = [UIButton buttonWithType:UIButtonTypeCustom];
   sidebarButton.bounds = CGRectMake(0, 0, sidebarButtonImage.size.width, sidebarButtonImage.size.height);
   [sidebarButton setImage:sidebarButtonImage forState:UIControlStateNormal];
   [sidebarButton addTarget:self action:@selector(onMenuPressed:) forControlEvents:UIControlEventTouchUpInside];
   UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:sidebarButton];
   [self.navigationItem setLeftBarButtonItem:leftButton];
}

加载此视图后,导航栏不会出现。

1 个答案:

答案 0 :(得分:2)

您的视图控制器必须位于导航控制器内。确保您的视图控制器是根视图或self.navigationController.viewcontrollers中的一个视图控制器

如果它未包含在导航控制器内,则您将没有任何栏。