不需要的双导航栏

时间:2012-06-26 00:24:23

标签: iphone xcode uinavigationcontroller uinavigationbar

当我点击屏幕时,我使导航栏(顶部栏)显示/消失,并且还位于背景图像的顶部。它有效,但有一个问题:我突然有两个导航栏!首先,一个带有一个名为“Back”的后退按钮,当我按下“Back”时,它弹出一个新的导航栏,后面有一个名为“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];
    }
}

1 个答案:

答案 0 :(得分:3)

通常,像你描述的重复导航栏是由两次推动同一个视图控制器引起的。您是否可以检查以确保只将单个视图控制器推送到导航堆栈(通过断点或记录?)。 wineDetailViewController是否已经在导航堆栈上?您还可以尝试记录self.navigationController.viewControllers的值以获取提示。

我还建议移动

self.navigationController.navigationBar.translucent = YES;

viewWillAppear和

self.wantsFullScreenLayout = YES;

到您的初始化程序(虽然我认为这不会解决您的问题)。