Dailycode.info

Short solution for short problems

iOS: Open second storyboard in modal with presentation curl.

I had a very large StoryBoard with a lot of relations. I started to group functionality and add the Views to different storyboards. Since iOS 7 and xcode 5 it came in a hurry, since the designer was crashing and messing up the layout.

First I just pushed the viewcontrollers in the navigation controller like this:

+(void) NavigateToCustomerLookupFrom:(UIViewController *)vc

{

    UIStoryboard * sb = [UIStoryboardstoryboardWithName:@"CustomerLookupStoryboard"bundle:nil];

    UIViewController * vcTo = [sb instantiateInitialViewController];

    

    [UIViewtransitionWithView:vc.viewduration:0.8options:UIViewAnimationOptionTransitionCrossDissolve

                    animations:^{

                        [vc.navigationController pushViewController:vcTo animated:NO];

                    }

                    completion:NULL];

    

}

That worked. But then I came up with a views that needed to be opened in a modal way. So this is the code to do just that. In this example I use the partial curl effect to open it:

+(void) NavigateToSignatureFrom:(UIViewController *)vc withSignee:(NSString *) Signee

{

    UIStoryboard * sb = [UIStoryboardstoryboardWithName:@"SignatureStoryboard"bundle:nil];

    UIViewController * vcTo = [sb instantiateInitialViewController];

    

    ((SignatureVC *) vcTo).Signee = Signee;

    

    [vcTo setModalTransitionStyle:UIModalTransitionStylePartialCurl];

    [vc presentViewController:vcTo animated:YEScompletion:nil];

}

The example also shows how to set properties of the destination controller.


iOS: Using multiple storyboards within a navigation controller.

I had a big story board file and I wanted to start to split it up in multiple storyboards containing views with shared functionality. First I found out how to open a different storyboard modally. But since the application uses a navigation controller at certain points, I also wanted to keep the navigation when opening some other storyboards. 

So iOS makes it really simple:

First instantiate the storyboard you want to navigate to (bundle can be nil if the story board is in the same bundle):

UIStoryboard * planningSB = [UIStoryboardstoryboardWithName:@"PlanningStoryboard"bundle:nil];

Then instantiate the initial view controller:

UIViewController * planningVC = [planningSB instantiateInitialViewController];

And last, just push this view controller into the view controllers collection of the current navigation controller.

[self.navigationControllerpushViewController:planningVC animated:YES];

Now the View controller of the second storyboard is loaded in the navigation controller. When pushed on the back arrow on the top, it will simply go back to the previous view controller and the second story board will be deallocated when the reference to its initial view controller is released.

Next is another example where I change the transition style:

UIStoryboard * planningSB = [UIStoryboardstoryboardWithName:@"PlanningStoryboard"bundle:nil];

UIViewController * planningVC = [planningSB instantiateInitialViewController];

 

[UIView transitionWithView:self.view duration:0.8 options:UIViewAnimationOptionTransitionCrossDissolve

                        animations:^{

                            [self.navigationController pushViewController:planningVC animated:NO];

                        }

                        completion:NULL];

 

 In my case I had a camera view that could be called from several views, I put this on a new storyboard and this works great. Since the camera view was also pointing to the search order view, I had to put the search order view also on a separate storyboard. Again my main story board got simpler.

So have a main story board, and separate as much as you can onto separate storyboards. I made a general class StoryBoardNavigation where I centralized all functions to call child storyboards.

Here is an example of this:

This function navigates to the storyboard called OrderLookupStoryboard and opens the view in start position.

+(void)NavigateToOrderLookupFrom:(UIViewController*)vc {UIStoryboard* sb =[UIStoryboard storyboardWithName:@"OrderLookupStoryboard" bundle:nil];UIViewController* vcTo =[sb instantiateInitialViewController];[UIView transitionWithView:vc.view duration:0.8 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{[vc.navigationController pushViewController:vcTo animated:NO];} completion:NULL];}

This function passes some parameters to the storyboard.

+(void)NavigateToCameraFrom:(UIViewController*)vc WithSelectedZone:(int)selectedZone {UIStoryboard* sb =[UIStoryboard storyboardWithName:@"CameraStoryboard" bundle:nil];MediaCapture* vcTo =[sb instantiateInitialViewController]; vcTo.selectedZone = selectedZone; vcTo.zoneSet = YES;[UIView transitionWithView:vc.view duration:0.8 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{[vc.navigationController pushViewController:vcTo animated:NO];} completion:NULL];}

This function opens the view in module transition style:

+(void)NavigateToSignatureFrom:(UIViewController*)vc withSignee:(NSString*)Signee{UIStoryboard* sb =[UIStoryboard storyboardWithName:@"SignatureStoryboard" bundle:nil];UIViewController* vcTo =[sb instantiateInitialViewController];((SignatureVC*) vcTo).Signee=Signee;[vcTo setModalTransitionStyle:UIModalTransitionStylePartialCurl];[vc presentViewController:vcTo animated:YES completion:nil]; 

}