不需要的双导航栏 [英] Unwanted double navigation bar
问题描述
当我点击屏幕时,我使导航栏(顶部栏)显示/消失,并且还位于背景图像的顶部。它有效,但有一个问题:我突然有两个导航栏!首先,一个带有一个名为Back的后退按钮,当我按下Back时,它会弹出一个新的导航栏,其中有一个名为Vinene的后退按钮,这是它返回的TableView的标题。那就是我想要保留的那个。我认为问题出在DetailViewController.m或MasterViewController.m中的didselectrowatindexpath中。希望有人能看到问题!
I made the navigation bar (top bar) appear/disappear when I tap the screen, and also lay on top of the background image. It worked, but with one problem: I've suddenly got two navigation bars! First, one with a back button named "Back", and when I press "Back" it pops up a new navigation bar with a back button named "Vinene", which is the title of the TableView it leads back to. Thats the one I want to keep. I think the issue is somewhere in the DetailViewController.m or in the didselectrowatindexpath in the MasterViewController.m. Hope someone can see the problem!
DetailViewController.m:
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:
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];
}
}
推荐答案
通常,像你描述的重复导航栏是由两次推动同一个视图控制器引起的。您是否可以检查以确保只将单个视图控制器推送到导航堆栈(通过断点或记录?)。 wineDetailViewController是否已经在导航堆栈上?您还可以尝试记录 self.navigationController.viewControllers
的值以获取提示。
Usually, a recurring navigation bar like you describe is caused by something like pushing the same view controller twice. Can you check to ensure you're only pushing a single view controller on to your navigation stack (via breakpoints or logging?). Is it possible that winesDetailViewController is already on the navigation stack? You can also try logging the value of self.navigationController.viewControllers
for a hint.
我还建议移动
self.navigationController.navigationBar.translucent = YES;
to viewWillAppear和
to viewWillAppear and
self.wantsFullScreenLayout = YES;
到您的初始化程序(虽然我认为这不会解决您的问题)。
to your initializer (though I don't think this will solve your problem).
这篇关于不需要的双导航栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!