不需要的双导航栏



我使导航栏(顶部栏)在点击屏幕时出现/消失,并且还位于背景图像的顶部。它奏效了,但有一个问题:我突然有两个导航栏!首先,一个带有名为"后退"的后退按钮,当我按"后退"时,它会弹出一个新的导航栏,其中包含一个名为"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];
    }
}

通常,像您描述的那样重复出现的导航栏是由诸如按两次相同的视图控制器引起的。您能否检查以确保仅将单个视图控制器推送到导航堆栈(通过断点或日志记录?是否有可能winesDetailViewController已经在导航堆栈上?还可以尝试记录 self.navigationController.viewControllers 的值以获取提示。

我还建议搬家

self.navigationController.navigationBar.translucent = YES;

查看将出现和

self.wantsFullScreenLayout = YES;

到您的初始值设定项(尽管我认为这不会解决您的问题)。

最新更新