Add StoryBoard to the existing UINavigation with Tab bar project - ios

I have an UI Navigation project with tab bar, each tab bar is contain XIB and ViewController, the project is loaded each ViewController from the App delegate by this method :
MyFourthView *fourthViewController;
fourthViewController = [[MyFourthView alloc] initWithTabBar];
localNavigationController = [[UINavigationController alloc]
initWithRootViewController:fourthViewController];
[localControllersArray addObject:localNavigationController];
Now I am trying to add storyboard to my project, and load it from the app delegate programmatically to be a fifth tab bar view, but I don't know how I can do that? because there is no XiB in the storyBoard so the above method isn't work ?

If the fifth navigation controller you want to add to your tab bar is the root/initial viewcontroller in your storyboard you can instantiate it like this:
UINavigationController *fifthNavigationController = [[UIStoryboard storyboardWithName:#"yourstoryboardname" bundle:nil] instantiateInitialViewController];
If its not, give it a storyboard id and instantiate it like this:
UINavigationController *fifthNavigationController = [[UIStoryboard storyboardWithName:#"yourstoryboardname" bundle:nil] instantiateViewControllerWithIdentifier:#"storyboardIdOfYourNavController"];

Apple documents switching to using Storyboards here:
http://developer.apple.com/library/ios/#releasenotes/Miscellaneous/RN-AdoptingStoryboards/index.html

Related

ViewDidLoad and WillHideViewController Not Called When Use UINavigationController as Child of UISplitViewController on iOS13

I have an apps with UISplitViewController as Root View, but for children of this view I use UINavigationController.
Although Master and Detail View is UIViewController, but I added this to UINavigationController before I set as Child of UISplitViewController, I did this because I need Title and UIBarButton, and also because I share this view for iPad and iPhone.
So this the snippet of my code:
MasterView _masterView = new MasterView;
UINavigationController _masterViewNavigation = new UINavigationController(_masterView);
DetailView _detailView = new DetailView;
UINavigationController _detailView Navigation = new UINavigationController(_detailView);
_splitView.ViewController = new UIViewController[]{_masterView, _detailView};
Everything was working before iOS 13. But when I run on iOS 13, ViewDidLoad of _masterView wasn’t called. While I need this to change image view on _masterView when the user makes changes on _detailView, although _masterView not shown.
Also WillHideViewController is not called, while I need this to add UIBarButtonItem on _detailView to show and hide _masterView.
Can you help me to find the solution?
Issue with iOS 13 Split view controller using IB. If you have navigation controller embedded to Master/Detail view controller it just loads the navigation controller.
To fix that issue create a custom class from UISplitViewController and assign that to your splitviewcontroller in storyboard and programatically add Navigation controller and masterViewcontroller to that UISplitViewController. That should load your view properly. This code goes in the viewdidload or willappear of the UISplitviewcontroller class.
Sample code. in Obj c
MasterViewController *master = [[MasterViewController alloc] init];
UINavigationController *tableViewNavigationController = [[UINavigationController alloc] initWithRootViewController:master];
UINavigationController *navC = [[UINavigationController alloc] init];
self.viewControllers = [NSArray arrayWithObjects:tableViewNavigationController,navC, nil];
This fixed my issue , Had similar issue after iOS13. Hope that help !

set same navigation bar in xib and storyboard

I am creating a Project In which I have FrontViewController And SlideOutMenu. On clicking MenuItem I want according view in the FrontViewController's subview. The FrontViewController is having Storyboard and all the subviews are created in .xib. And I am getting subview but not getting the navigation bar as in the Storyboard.
So my question is:
How to get the same navigation bar in the xib as the storyboard has?
I have tried:
UINavigationController *navigationController =
[[UINavigationController alloc]
initWithRootViewController:bookingViewController];
[_swReveal
pushFrontViewController:navigationController animated:YES];
But I am not getting anything.

Bottom Bar Items not appearing in presentViewController

In my app, I dynamically load a set of images, and when a user taps on an image, it opens up a new ViewController (MediaPreview) that opens up a large preview of the image.
I create the MediaPreview controller as follows:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
mediaPreviewVC = (MediaPreviewViewController *)[storyboard instantiateViewControllerWithIdentifier:#"MediaPreviewViewController"];
mediaPreviewVC.selectedImageURL = [NSString stringWithFormat:#"%#",gestureRecognizer.view.tag];
navigationController = [[UINavigationController alloc] initWithRootViewController:mediaPreviewVC];
[self presentViewController:navigationController animated:YES completion:nil];
This creates a ViewController that looks like this:
However, the bottom navigation bar appears to be missing, which is outlined in my storyboard:
How can I ensure that the bottom navigation bar buttons appear in my view?
You are creating the navigation controller out of whole cloth:
navigationController = [[UINavigationController alloc] initWithRootViewController:mediaPreviewVC];
alloc-init means "make me a completely fresh, separate, generic one". Thus, navigationController is not the navigation controller in your storyboard. It's a completely new and different navigation controller. Thus, what's in your storyboard is irrelevant.
If you wanted the navigation controller from your storyboard, you needed to instantiate the navigation controller from the storyboard. Or, if you're doing this intentionally, then the bottom bar won't be visible unless you explicitly make it visible, because by default it isn't (it's obvious how to make it visible explicitly).
But then in that case, if you meant to pull it out of the storyboard, then your whole code is probably wrong, because the one in the storyboard probably already has the correct root view controller as well.

Pushing a view controller onto a navigation controller from a tab bar button

I have a tab bar controller with a button like so:
- (void) addButtonPressed:(UIButton *) sender
{
[sender setBackgroundColor:[UIColor regularColor]];
PostViewController *post = [[PostViewController alloc] init];
[self.navigationController pushViewController:post animated:YES];
}
This code runs but the PostViewController is never shown and the tab bar controller remains.
How do I get to push to a new controller?
The NavigationController was created and StartViewController was add as rootController.
Then in StartViewController I have:
TabBarController *tab = [[TabBarController alloc] init];
// Presentation
[self presentViewController:tab animated:NO completion:nil];
in tab bar you need to create separate Navigation Controllers.
Suppose there are 3 tabs A, B and C. All the three tabs have functionality of navigation from one view to another. than you need to create three separate Navigation controllers eact pointing to Tab A, B and C. In this way you can navigate to any class within the specific Tab.
Check out this link for more details.
Hope this will help you. Happy coding :)
You may need to embed your tab bar controller within a navigation controller, In your storyboard click on your tabbarController so that it is highlighted with all the blue lines and then go to Editor in Xcode choose embed IN> UINavigationController ..If you want to do it programatically then in your AppDelegate where you setup your Window just Use This::
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:tabBarController];
navigationController.toolbarHidden=YES;
navigationController.navigationBarHidden=YES;
self.window.rootViewController =navigationController;
if you are using .xib then you have to use NSBundle to load nib
if you are using storyboard then you need to use prepareForSegue to pass on data or just display it out

Splitting Storyboard at UITabBar level

I'm searching for a solution to split Storyboard at UITabBar level.
I have an app with 5 tab and i want to manage every single tab with a different storyboard.
The structure would be a simple minimal storyboard with the tab bar controller and 5 bigger storyboards with every tab viewcontrollers (and segues) which must inherit the tab bar.
Does everyone ever splitted the storyboard like this ? Any clue?
Thanks
I think it could be possible, this should go in "viewDidLoad" of your custom UITabBarController...
NSMutableArray *controllersArray = [[NSMutableArray alloc] init];
// Load the initial UIViewController from every Storyboard
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Storyboard1" bundle:nil];
UIViewController *first = [sb instantiateViewControllerWithIdentifier:#"firstViewController"];
[controllersArray addObject:first];
// Repeat the process with the rest
...
// Set your controllers
self.viewControllers = [controllersArray copy];
Remember to set an Storyboard ID for every main UIViewController, in the example is 'firstViewController'.
we used RBStoryboardLink from: http://robsprogramknowledge.blogspot.co.il/search/label/UIStoryboard
to solve this issue

Resources