1
votes

I have many storyboards in my project to have modules with specific functionalities. In one of my storyboard, I have a navigation controller, which push the initial view controller of another storyboard. When I push it, the navigation bar is removed and there is no way to get this specific bar back. When I put another navigation controller in my new storyboard, the navigation bar is resetted with an ugly transition (it comes from the right and replace the older one).

This is how I push my new storyboard's view controller :

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:aStoryboardName bundle:nil];
UIViewController *SideBarInitialViewController = [storyboard instantiateInitialViewController];

UIStoryboardSegue *segue = [[GDFromRightCustomSegue alloc] initWithIdentifier:aSegueIdentifier source:aSource destination:SideBarInitialViewController];
[segue perform];

I perform a custom segue as well to get rid of the basic animation (the view coming from below) :

UIView *sourceView = [self.sourceViewController view];
UIView *destinationView = [self.destinationViewController view];

CGFloat screenHeight = [[UIScreen mainScreen] bounds].size.height;
CGFloat screenWidth = [[UIScreen mainScreen] bounds].size.width;

destinationView.frame = CGRectMake(screenWidth, 0.0, screenWidth, screenHeight);

UIWindow *window = [[UIApplication sharedApplication] keyWindow];
[window insertSubview:destinationView aboveSubview:sourceView];

[UIView animateWithDuration:0.4 animations:^{
    destinationView.frame = CGRectOffset(destinationView.frame, -screenWidth, 0.0);
    sourceView.frame = CGRectOffset(sourceView.frame, -screenWidth, 0.0);

} completion:^(BOOL finished){
    [self.sourceViewController presentViewController:self.destinationViewController animated:false completion:nil];
}];

Is there a way to push the new storyboard without animate the navigation bar, or even better, to have the older navigation controller in my new storyboard ?

1

1 Answers

0
votes

In your source storyboard drag a new UIViewController and then drag a ** Modal segue** to this new UIViewController from your source ViewController. Click on this segue and then in the attributes Inspector add a Identifier of segue (let say "newSegue") Identifier must be unique. Also set segue type to "Custom " and write "newSegue" in Segue Class

Now add a catagory on UIStoryBoardSegue with name newSegue and in the .m file write these two methods.

- (id) initWithIdentifier:(NSString *)identifier
                   source:(UIViewController *)source
              destination:(UIViewController *)destination
{
    return [super initWithIdentifier:identifier
                              source:source
                         destination:[[UIStoryboard storyboardWithName:@"YourDestinationStoryBoardName" bundle:nil] instantiateInitialViewController ]];
}

- (void)perform
{

    UIViewController *source = (UIViewController *)self.sourceViewController;

   [source presentViewController:self.destinationViewController
                                          animated:YES
                                        completion:Nil];

}

Now in your source ViewController when you want to presenth new View Controller write this line

[self performSegueWithIdentifier:@"newSegue" sender:nil];

Must Remember to replace "YourDestinationStoryBoardName" with your actual destination StoryBoard name in the above function.

Try this Hope this will work fine.