2014-05-13 81 views
0

看來我做錯了什麼,但我不明白是什麼。我有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]; 
} 

加載此觀點的導航欄不會出現後。

+0

這不是你如何做到這一點。這是你的應用程序的根視圖控制器嗎?你在使用storybaords/xibs還是以編程方式進行編程? – CW0007007

+0

'[self.view addSubview:self.navigationController.view];'那應該做什麼? – Jkmn

+0

@ CW0007007我正在以編程方式進行。它不是根視圖控制器,但它在裏面navigationController.viewcontrollers –

回答

2

您的視圖控制器必須位於導航控制器內部。確保您的視圖控制器是根視圖或self.navigationController.viewcontrollers中的一個視圖控制器。

如果它不包含在導航控制器內,則不會有任何條。

+0

你說得對,我把這個控制器作爲根視圖控制器,當我打開適當的視圖,並解決了問題。謝謝 –