UINavigation PushViewController Doesn't Display Next View, But Runs The Code

1.3k views Asked by At

The problem, My home screen is wrapped in a UINavigationController, when I push to the next controller it's fine, but then when I use the left swipe to go back to the home screen then click on the button to take me to the next controller sometimes it works fine about 60% other times it just hangs there. I can see the code executing in my logs as if the view controller has been presented but it's not on screen...

So at this point the whole UI is unresponsive, the only thing I can do is swipe from Left to Right like I want to go back to another page, but this is where it gets funky, the screen that I was trying to display then slides in view from the right side of the screen.

When I let go it reloads the home view, then the app works as designed.

I have no idea whats going on with this thing... Below is my code for presenting the next view:

    NextViewController *nextViewController = (NextViewController*)[self.storyboard instantiateViewControllerWithIdentifier:@"NextViewController"];
    nextViewController.nameString = [[self.topArray objectAtIndex:[indexPath row]] objectForKey:@"Name"];
    nextViewController.championMCID = [[self.topArray objectAtIndex:[indexPath row]] objectForKey:@"UserId"];
   [self.navigationController pushViewController:nextViewController animated:YES];

When I get to the next screen because i'm hiding the navigationbar, I am setting the following:

[[self navigationController]setNavigationBarHidden:YES animated:NO];

self.navigationController.interactivePopGestureRecognizer.delegate = self;

And that's it, not quite sure what's going on but any help would be great help thanks.

2

There are 2 answers

0
C-H-E-F On BEST ANSWER

I integrated a left side menu, that operates as a settings screen, and I believe that the:

self.navigationController.interactivePopGestureRecognizer.delegate = self;

And that left side menu were clashing, when I say clashing I mean, when I pop the next view controller, I believe somewhere in the stack that the views got tangled up. So when I push to another view, the app doesn't know rather to use the left side menu or to use the navigation controller without the left side menu...

So instead of allowing the:

self.navigationController.interactivePopGestureRecognizer.delegate = self;

I decide to place this code in my viewwillappear method:

self.navigationController.interactivePopGestureRecognizer.delegate = self;

NSUInteger viewControllerCount = self.navigationController.viewControllers.count;

NSLog(@"viewControllerCount %ld", viewControllerCount);

    if (viewControllerCount == 1)
    {

self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }
    else
    {

self.navigationController.interactivePopGestureRecognizer.enabled = NO;
    }

I placed this code in the initial navigation controller so whenever I push, the left side menu will be on every screen within the app, and then I implemented a back button on each screen so that I can pop the views instead of sliding left, I didn't want to implement the UINAVIGATIONBAR at the top because I need that small piece of screen as well to display everything haha...

I hope this helps anyone in the future that may have the same issues, good luck, happy coding.

0
babatunde adewole On

I had this issue too and what I noticed was that my current view controller was not embedded in a UINavigation controller so on using navigationController?.pushViewController(viewController, animated: true) my current navigationController was null