Bottom Bar Items not appearing in presentViewController - ios

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.

Related

UINavigationController embedded in container view from Storyboard won't push UIViewController

In my storyboard for a container class, I have created a full-screen Container View with an embed segue that's attached to a UINavigationController. I'm trying to test this by pushing a viewController programmatically like below:
UIViewController* test = [[UIViewController alloc] init];
test.view.backgroundColor = [UIColor redColor];
UINavigationController* navC = [[RootController mainStoryBoard] instantiateViewControllerWithIdentifier:#"containerNav"];
[navC pushViewController:test animated:NO];
navC is successfully initialized as the navigation controller, but the pushViewController call seems to do nothing. I still just see an empty navigation controller on the screen (default navigation bar with black view). I also tried a similar test with the setViewControllers method, which also failed. Are navigation controllers not meant to be embedded into container views?
UINavigationController needs a UIViewController at the bottom of its stack from when it is first created, (and it can't 'pop' that one). In other words it can't begin with an empty stack, you should be adding/embedding one viewController inside it in the xib/storyboard, then I expect it'll work with what you're doing here
I think you may need to just set the viewControllers property on the Nav Controller, like this:
[navC setViewControllers(#[test] animated: NO]

Xcode 6 - Added Navigation Controller to storyboard, but not appearing in app

I added a Navigation Controller to my storyboard and it appears like so:
Now in the table view controller, I gave the TableViewController a storyboard id and class to a TableViewController Controller
When I run my app, I don't see the Navigation Bar at the top. This has been extremely frustrating and can't find a solution anywhere. PLEASE HELP
To get to the scene, someone clicks a button and this code runs and it goes to my Table View Controller:
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Storyboard" bundle:nil];
LHFileBrowser *LHFileBrowser = [storyBoard instantiateViewControllerWithIdentifier:#"FileBrowser"];
[self.navigationController pushViewController:LHFileBrowser animated:YES];
[self presentViewController:LHFileBrowser animated:YES completion:nil];
The error is in your code.
If you want to (modally) present a view controller when the user presses a button, you need to present the navigation controller (which will contain the table view controller), not the table view controller itself.
Right now, you're presenting the view controller, which won't show it being embedded in a navigation controller.
Also, you're mixing up two different approaches, by trying to push a view controller onto a navigation controller stack, and also presenting the view controller.
Code Sample:
Here's what you apparently mean to do:
UIStoryboard *storyboard = self.storyboard;
UINavigationController *navigationController = [storyboard instantiateViewControllerWithIdentifier:#"MyNavigationControllerID"];
LHFileBrowser *rootViewController = [navigationController topViewController];
// Configure your LHFileBrowser view controller here.
rootViewController.someProperty = ...;
// Modally present the embedded view controller
[self presentViewController:navigationController animated:YES completion:nil];
If you want to change the presentation or transition style, you can set those details in your storyboard.
You didn't explain why you had to programmatically add buttons, but Storyboard segues would have instantiated and presented an embedded view controller for you, without you having to have done it in code.
The more you can do in Storyboard, the less code you have to maintain, support, and update, and the more likely your app will still work properly when a new SDK is released.
Update:
The better way to do this is to let Storyboard do it for you, by adding a segue from the button to the navigation controller that you want to present.

iOS) How to make Tab View with fixed view at the top and bottom

I'm in trouble making tab view as I want.
Here's my plan, At the top and bottom, there is each fixed view.
so there must be in-between view.
At there I want to insert Tab bar and subviewcontrollers.
But by using storyboard and tabbarController,
I have to make same fixed views for every sub viewcontroller, isn't it?
How can make it right?
You can import view from the tab bar controller to the in-between view in the View controller.
Give a storyboard id to the tab bar controller. Here I am using "Tab".
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UITabBarController* tab = [storyboard instantiateViewControllerWithIdentifier:#"Tab"];
tab.view.frame = self.inBetweenView.bounds; // replace with your view's name
[self.inBetweenView addSubview:tab.view];
[self addChildViewController:tab];
[tab didMoveToParentViewController:self];

How do I instantiate a storyboard with a given root viewcontroller and initial viewcontroller?

I have a storyboard in my application with a navigation controller and several views. This automatically puts a navigation bar with a back button into any views that are not the root view.
However, sometimes I navigate away from this storyboard to an individual nib. I want to navigate back to the storyboard, but not necessarily to the original root view. I currently use this method to do so:
+(void) TransitionOnStoryboard:(NSString*)storyboard to:(NSString*)identifier withViewController:(UIViewController*)viewController
{
UIStoryboard *sb = [UIStoryboard storyboardWithName:storyboard bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:identifier];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[viewController presentViewController:vc animated:YES completion:NULL];
}
This shows the view I want but without the navigation bar. How do I specify my navigation controller or root view, such that the app knows to put a navigation bar with a back button in?
Thanks
The answer is to leave your navigation controller underneath the view controller you add from a nib.
Present the nib as a full0-screen modal. That gets rid if your navigation bar, as desired. From that new view controller, you can push more modals, add a navigation controller, or whatever.
Note that you could do all of this and stay inside your storyboard as well.
Once you are done, dismiss the modal to reveal your navigation controller, and you are back in business with your storyboard. You can push a new view controller onto your navigation controller without animation and it should appear as the front-most VC when you pop the modal that came from a nib.
I'm sure that this isn't the ideal way to solve this problem, but it did work very nicely for me.
Essentially, I removed all the views from the view controller that had been generated since I navigated away from the storyboard, but before the current view and popped the current view. In this case, these views were of one class (CheckboxListViewController) and so could be removed quite simply as below:
+(void) navigateToMainMenu:(UINavigationController*)navigationController
{
[QuickView removeFromNavigationController:navigationController allOfViewControllerWithClass:[CheckboxListViewController class]];
[navigationController popViewControllerAnimated:YES];
}
+(void) removeFromNavigationController:(UINavigationController *)navigationController allOfViewControllerWithClass:(Class)viewControllerClass
{
NSMutableArray *keptViewControllers = [[NSMutableArray alloc]init];
for (UIViewController *viewController in navigationController.viewControllers)
if (![viewController isKindOfClass:viewControllerClass])
[keptViewControllers addObject:viewController];
navigationController.viewControllers = keptViewControllers;
}
(note- QuickView is the name of the class that contains these methods.).
Any other classes that you do not want your pop to navigate back to can be removed by calling:
[QuickView removeFromNavigationController:navigationController allOfViewControllerWithClass:[YourClassName class]];
In the navigateToMenu method.

Navigation Bar & Navigation Toolbar NOT from App Delegate

I'm new to xcode ios 7.
I've struggling a lot with navigation controls building app for iPhone ios7.
I don't want to use storyboard. I prefer to do it programmatically.
What i am trying to do.
I know how to create NavigationBar & Navigation Toolbar via AppDelegate.m
But if it's possible i don't want to do it, because let's assume i want in FirstViewController to show just simple button "Go to Second View Controller" (No Navigation Bar or Toolbar here).
And now in SecondViewController i want to create Navigation Toolbar (bottom) with 4 different tabs linking to ViewControllers!
But the trick is, i want to maintain different Navigation Bar (top) for every ViewController (as you can see in this screenshot).
Here is my Xcode Project File
And here is screenshot form Fancy app showing what i am trying to achieve.
Thanks a lot in advance!
Just to give you an idea, When you tap the button on your first view controller, you can create a UINavigationController and set your second view controller as its root view controller. This way, your first view controller remains no nav bar view and the second view controller holds a Navigation controller. Try something like below:
-(IBAction)goToSecondVC:(id)sender // An action for the button in your first VC
{
SecondViewController *secondVC = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil]; //Init with second view controller
UINavigationController *secondNavVC = [[UINavigationController alloc] initWithRootViewController:secondVC]; // create a navigation controller and set the root as your second view controller
[self presentViewController:secondNavVC animated:YES completion:nil]; // and then present it with anim or no anim..
}

Resources