Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unwanted double navigation bar

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:

@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];
    }
}
like image 667
ingenspor Avatar asked Jun 26 '12 00:06

ingenspor


People also ask

Which button is to the left of the navigation bar?

The first navbar has the navigation links aligned to the left and the login link to the right. The second navbar has the navigation links to the left and the “register” and “logout” buttons to the right. Unlike the previous example, the navbars in this example are not responsive.

What is the difference between the second navbar and navbar toggle button?

The second navbar has the navigation links aligned to the right and plaintext with a hyperlink aligned to the left. Both the navbars are responsive to the screen size. The navbar toggle button appears when the screen size reduces and disappears when the screen size increases. The toggle button when clicked displays the navbar. Attention reader!

Can you have a double row navbar in Bootstrap 4?

Double Row Navbar with Dropdowns Bootstrap Snippets Library/ Navbars Examples This example demonstrates how you can have a multiple row navbar that collapses. Bootstrap 4 See the Pen Double Row Navbar with Dropdownsby Jacob Lett (@JacobLett) on CodePen. Code Snippet Preview Advertise Here View Demo Recent Bootstrap Examples

Are the navbars responsive to the screen size?

The first navbar has the navigation links aligned to the left and the login link to the right. The second navbar has the navigation links to the left and the “register” and “logout” buttons to the right. Unlike the previous example, the navbars in this example are not responsive. The navbars do not adapt to the screen size.


1 Answers

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.

I would also suggest moving

self.navigationController.navigationBar.translucent = YES;

to viewWillAppear and

self.wantsFullScreenLayout = YES;

to your initializer (though I don't think this will solve your problem).

like image 106
Jesse Rusak Avatar answered Oct 02 '22 03:10

Jesse Rusak