presentModalViewController not displaying toolbar? - ios

I have a viewcontroller I am trying to display as a UIModalPresentationFormSheet, however it does not show its UIToolbar. How can I make a toolbar show up on it?
ConnectionEditViewController * connectionEditViewController = [[ConnectionEditViewController alloc] initWithNibName:#"ConnectionEditViewController" bundle: nil];
connectionEditViewController.modalInPopover = YES;
connectionEditViewController.modalPresentationStyle = UIModalPresentationFormSheet;
connectionEditViewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController: connectionEditViewController animated: YES];

Create a UINavigationController instance, set the rootViewController to be your connectionEditViewController, then configure the modal properties for the UINavigationController and present that.
If this is on iPad, it should pop up the view with the Navigation Bar as a grey toolbar at the top.
Configure the navigationItem of the connectionEditViewController to configure the nav bar.

Related

Navigation bar not accessible when using SWRevealViewController with UITabBarController

I have set Sliding menu(Rear view controller) using SWRevealViewController with a UITabBarController (front view controller). Below is the piece of code I used:
RearMenuViewController *rearViewController = [[RearMenuViewController alloc] init];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
UINavigationController *navTabController = [[UINavigationController alloc] initWithRootViewController:_tabBarController];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:navTabController];
revealController.delegate = self;
revealController.rightViewController = nil;
self.viewController = revealController;
self.window.rootViewController = revealController;
This works fine and I can toggle between the rear menu and tab bar items using swipe gesture.
But I am not able to set the navigation title for each tab bar item nor I can add any bar button on navigation bar. I can only see blank navigation bar for every tab bar item.
Also would like to share that I am NOT using storyboard in the project.So, I need to set the title and a bar button through code only.
Please let me know if any other info is required.
I managed to access the navigation bar for each tab bar item like this:
UINavigationController *currentNav = (UINavigationController *)self.tabBarController.parentViewController;
UINavigationItem *navItem =(UINavigationItem *) [currentNav.navigationBar.items firstObject];
navItem.title = #"Dashboard";
Need to write this in each item (view controller) of tab bar if we need to have different titles for each tab bar item.
Please let me know if there is a better way to achieve this.

Status bar color does not match navigation bar

I have a view controller I am presenting modally. I want the status bar color to match the navigation bar color.
I have set UIViewControllerBasedStatusBarAppearance to YES because I don't want this change across the entire application.
I am setting self.navigationController.navigationBar.barTintColor but this is only changing the navigation bar color. The status bar remains a lighter color.
I have tried various combinations of setNeedsStatusBarAppearanceUpdate and preferredStatusBarStyle but none have any effect.
View controller is launched like so:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:searchController];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];
My steps are below, check where you go wrong:
Create 2 view controller like below, you can let vc1 embed in a navigation controller:
In the vc1, you drag a action of the button:
Code is below:
- (IBAction)clickAction:(UIButton *)sender {
UIStoryboard *sb = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
ViewController2 *searchController = [sb instantiateViewControllerWithIdentifier:#"ViewController2"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:searchController];
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];
}
Then in the vc2, you set the title:

tab bar not displayed when added to navigation controller IOS

I have a navigation controller which has view controller(VC1) . This view controller has 3 button out of which 1 directs to a tab bar controller. From tab1 of the tab bar controller a button is there which navigates to a View controller(vc2).
The problem is VC2 is not displaying the tab bar. How can I make my VC2 display the tab bar.
Navigation Controller—> View Controller-->Tab bar Controller —>Tab1 -> View Controller (does not show tab bar)
I am doing this in IOS
Using a tabbarcontroller within a navigation controller is not recommended by Apple. However it is possible to do so.
In the VC1, write the following code.
UITabBarController *tabBarController = [[UITabBarController alloc] init];
MyStartViewController *startController = [[MyStartViewController alloc] initWithNibName:#"MyStartViewController" bundle:Nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:startController];
SecondViewController *viewController2 = [[SecondViewController alloc] initWithNibName:#"SecondViewController" bundle:nil];
self.viewControllers = #[navController, viewController2];
[self.navigationController pushViewController:tabBarController animated:YES];
Now within startController, add a UIButton. And in the button action, push the new VC2 from it.
Button action:
- (IBAction)buttonPressed {
MyViewController2 *vc2 = [[MyViewController2 alloc] initWithNibName:#"MyViewController2" bundle:nil];
[self.navigationController pushViewController:vc2 animated:YES];
}
Hope this will serve your purpose.

Presenting a UINavigationController from a UIViewController doesn't have default cancel button

I am trying to present a UINavigationController modally from a UIViewController. From previous experience, I'm pretty sure that when I do this there should be a cancel button by default in the navigation bar, however with the following code the navigation bar is completely blank. Any ideas?
UIViewController *rootVC = [[UIViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootVC];
[self presentViewController:navController animated:YES completion:nil];
You will not get any bar button items by default. You need to either add the button before presenting, or, more correctly, add the button from inside the root view controller. Normally, you want to have delegation set up, where the presented view controller notifies the presenting view controller that it should dismiss it. Self-dismissing from inside the root view controller is usually not recommended.
– presentViewController:animated:completion: only going to present your view controller as a modal view controller, even you set up that as a navigation controller. the easiest solution in your case is in the navController set the left bar button as the cancel button, and call dismiss when click that button,
UIBarButtonItem *cancelButton= [[UIBarButtonItem alloc] initWithTitle:#"Cancel" style:UIBarButtonItemStyleBordered target:self action:#selector(dismissViewController)];
navController.navigationItem.leftBarButtonItem = cancelButton;
- (void)dismissViewController
{
[self dismissViewControllerAnimated:YES completion:nil];
}
Hope that would help.

load page with pushViewController on tabbar

I have UIViewController with tabbar botton, and navigation bar and navigation item,
when I press on my button in navigation Item I want to load a view, I don't know how to load this view on tabbar,
would you please help me,thanks in advance!
-(IBAction) infoPage:(id)sender
{
InfoCtrol *i = [[InfoCtrol alloc] initWithNibName:#"InfoCtrol" bundle:nil];
[self.navigationController pushViewController:i animated:YES];
}
This will load the InfoCtrol controller and set the Touch UpInside Event in xib to the infoPage method
Do you mean you want to hide the tab bar when you push new controller in navigation?
If true. There is a property hidesBottomBarWhenPushed in the UIViewController class.
// Instead of adding ViewController to TabbarController, add NavigationControllers.
// Eg.
UINavigationController *NavController = [[UINavigationController alloc] initWithRootViewController:_viewCtrl1];
[watchListNavController.navigationBar setTintColor:[UIColor blackColor]];
_tabC = [[UITabBarController alloc] init];
_tabCt.viewControllers = [NSArray arrayWithObjects:NavController,_viewCtrl2,_viewCtrl3, nil];
// Now you can use Push and Pop In your _viewCtrl1.
// Do same with all the viewController

Resources