2012-06-26 103 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 –