2012-06-26 71 views
5

當我點擊屏幕時,導致我導航欄(頂部欄)出現/消失,並且也位於背景圖像的頂部。它的工作,但有一個問題:我突然有兩個導航欄!首先,有一個後退按鈕命名爲「後退」,當我按下「後退」時,它會彈出一個新的導航欄,並帶有名爲「Vinene」的後退按鈕,這是它返回的TableView的標題。這就是我想要保留的那個。我認爲這個問題在DetailViewController.m或MasterViewController.m的didselectrowatindexpath中。希望有人能看到問題!不需要的雙導航欄

DetailViewController.m:

@interface WinesDetailViewController() 

@end 

@implementation WinesDetailViewController 

@synthesize wineDictionary; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) { 
    // Custom initialization 
} 
return self; 
} 

- (void)viewDidAppear:(BOOL)animated 
{ 
[super viewDidAppear:animated]; 

} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
// Do any additional setup after loading the view. 

self.navigationController.navigationBar.translucent = YES; 
         self.wantsFullScreenLayout = YES; 

UITapGestureRecognizer *tap = [[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideShowNavigation)] autorelease]; 
                             tap.numberOfTapsRequired = 1; 
                           [self.view addGestureRecognizer:tap]; 
} 

- (void) hideShowNavigation 
{ 
[self.navigationController setNavigationBarHidden:!self.navigationController.navigationBarHidden]; 
} 

- (void)viewDidUnload 
{ 
[super viewDidUnload]; 
// Release any retained subviews of the main view. 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
return (interfaceOrientation == UIInterfaceOrientationPortrait); 
} 

- (BOOL)hidesBottomBarWhenPushed{ 
return TRUE; 
} 


@end 

MasterViewController.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    { 
    [tableView deselectRowAtIndexPath:indexPath animated:YES];  

    NSDictionary *dictionary = [wine libraryItemAtIndex:indexPath.row]; 

    if (winesDetailViewController == nil) { 
     // Init the wine detail view 
     winesDetailViewController = [[WinesDetailViewController alloc] init]; 
    } 
    // Here you pass the dictionary 
    winesDetailViewController.wineDictionary = dictionary; 

    [self.navigationController pushViewController:winesDetailViewController animated:YES]; 
    } 
} 
+0

張貼圖片請 – Legolas

回答

3

通常情況下,像一個反覆出現的導航欄你的描述是通過像推了同樣的觀點控制器兩次造成的。你可以檢查以確保你只是將單個視圖控制器推到導航堆棧上(通過斷點或記錄?)。 winesDetailViewController是否可能已經在導航棧上?您也可以嘗試記錄self.navigationController.viewControllers的值作爲提示。

我也建議移動

self.navigationController.navigationBar.translucent = YES; 

到viewWillAppear中和

self.wantsFullScreenLayout = YES; 

到您的初始化(雖然我不認爲這將解決您的問題)。

+0

我想這就是問題,這聽起來很邏輯。我嘗試將som數據從tableview傳遞到詳細視圖,但這很棘手,因爲我是新手。我製作了一個從原型單元格到故事板中詳細視圖的故事板連接,以及我在我的問題中發佈的didselectrowatindexpath代碼。迄今爲止,除了雙槓之外,它工作得很好。 – ingenspor

+0

如果你以這種方式使用故事板,你可能想使用類似這個問題的建議;不要推自己的詳細視圖控制器。 http://stackoverflow.com/questions/8130600/use-didselectrowatindexpath-or-prepareforsegue-method-for-uitableview –