How to hide the NavigationBar when i use SWRevealViewController embed in UINavigationController? - ios7

When i use SWRevealViewController as initial view or not embedded in UINavigationController the result is as i expected:
but when the SWRevealViewController comes from UINavigationController tee result is:
How can i avoid the NavigationBar presented in the Rear view?

Please add the following code to the viewWillAppear: method of the viewcontroller whose navigation bar you need to hide.
[super viewWillAppear:YES];
[self.navigationController.navigationBar setHidden:YES];
[self.navigationController.navigationBar.backItem setHidesBackButton:YES];

Try, this code for rear view controller
- (void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBar.hidden = YES;
}

If you really need Navigation Controller on top of SWRevealViewController:
You got to hide navigation bar from navigation controller of your SWRevealViewController.
U can do this in IB (assuming you are using Storyboards):
Select Navigation Controller in your Storyboard
Open Attributes inspector
Find section "Navigation Controller", uncheck "Shows Navigation Bar"
Next, If you want navigation bard in front view controller, then attach it to separate Navigation Controller. You will have two Navigation Controllers, think on which one you want to push - it will have different effect.

Related

Putting a Navigation Controller inside a UIScrollView

I have a UIScrollView that houses three UIViewControllers so that I can swipe between them like the view setup in SnapChat.
In my ViewController on the very right of the UIScrollView I want the user to be able to select things and then navigate to a new page. So essentially I want the right-most UIViewController to be a Navigation Controller with a nav bar and and View Controllers I navigate to from this page should also have a nav bar and a Back button as the UIBarButtonItem in the top left as standard.
I went about it the normal way, just taking the View Controller and selecting "Embed In Navigation Controller" and looking at the storyboard it looks right, but if I run it, there's no nav bar at the top of the view controller.
I have the nav bar visibility set to "Show Navigation Bar" but still nothing.
Any help appreciated
Edit
The issue is more than likely to do with how I add the view controller to the UIScrollView which is as follows:
let settingsStoryboard = UIStoryboard(name: "SettingsView", bundle: nil)
let settingsViewController = settingsStoryboard.instantiateViewController(withIdentifier: "SettingsViewController")
self.addChildViewController(settingsViewController)
self.scrollView!.addSubview(settingsViewController.view)
So I'm only adding the view. So how would I add it as a Navigation Controller? Or can that be done?
The Problem you are facing is that you are adding your view controller directly inside the scroll view but you should add the navigation controller inside the ScrollView.
So go to story board create a StoryboardID for that navigationController which is attached to SettingsViewController and then replace the SettingViewController ID with your navigationController's Storyboard ID.
maybe use addChildViewController
- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(5_0);

How to specify the left, right, or title View button in XIB

I do not want to create a custom navigation bar.
I am pushing a UIViewController and I want to customize how the navigation bar looks for that UIViewController
In story board, we just specify the segue and a nav bar show up on the screen. We just drag and drop UIBarItem to the left and right.
In XIB, the navigationBar simply doesn't show up.
I can add navigation Item but the one I added is ignored.
I've heard that there used to be an outlet called navigationItem but it's deprecated for reason I do not know.
I can add UINavigationBar, however that would be adding my own custom bar. I want the navBar that's provided by UINavigationController.
The appearance of the Navigation Bar in the storyboard designer is just there to illustrate how your screen will look when you load your ViewController inside a UINavigationController. It doesn't mean that you actually have a navigation controller in your app.
You need to add a UINavigationController to your storyboard (probably as the first scene), and then connect your ViewController to it (as the root view controller).
Then you should be able to set your title in the storyboard designer, and drag bar button items onto the navigation bar.
See also the answer to this question.
You can setup it in code.
- (void)viewDidLoad
{
[super viewDidLoad];
self.title = #"Title";
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"Back"style:UIBarButtonItemStyleBordered target:self action:nil];
self.navigationItem.rightBarButtonItem = "Create button" ;
self.navigationItem.leftBarButtonItem = "Create button" ;
self.navigationItem.titleView = "Create custom title view";
}
I think this is the actual way apple want this to be implemented.
Put UINavigationBar
Set outlet to the UINavigationItem
This is the catch
Override navigationItem property to return the UINavigationItem you created.
That's it.
-(UINavigationItem *) navigationItem
{
return self.navigationItem1;
}
If your navigationItem is still in the UINavigationBar, I think you will need to have a strong outlet to the UINavigation Bar too. Please correct me if I am wrong here.

Top Bar does not appear for presentModalViewController

I've created a UIViewController subclass called addItemToListViewController. I selected add an "xib" as well, and just created a simple page with a couple of labels and a textField. In the interface builder I selected "Top Bar - Navigation Bar" so that when it is put on the stack when the application runs it will have a top bar that will match the initial main window. In the Interface builder it shows the top border, but when I run the application in the simulator the top bar is not present once the view is displayed.
Here is the code I placed in the rootViewController to present the view controller
- (IBAction)addButtonPressed:(id)sender
{
AddItemToListViewController *addItemToListViewController = [[AddItemToListViewController alloc] initWithNibName: #"AddItemToListViewController" bundle:nil];
[self presentModalViewController: AddItemToListViewController animated: YES];
[AddItemToListViewController release];
}
I'm only able to have the top bar present if I manually add a Navigation bar to the xib. If I must add a Navigation bar to my xib, what is the purpose of the "Top Bar" attribute?
- (IBAction)addButtonPressed:(id)sender
{
AddItemToListViewController *addItemToListViewController = [[AddItemToListViewController alloc] initWithNibName: #"AddItemToListViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addItemToListViewController];
[self presentModalViewController: navController animated: YES];
[AddItemToListViewController release];
[navController release];
}
That "top bar - Navigation bar" in InterfaceBuilder is what's known as a "Simulated Metric". It's there to help you lay out your view with correct spacing when other visual elements - the status bar, navigation bar, or tab bar - might consume some of the device's screen real estate. It doesn't actually do anything other than shrink the vertical dimensions of the view defined by the NIB. The purpose is to help you layout your view, not to actually create a component that will appear in your app.
If you want a navigation bar, then you have two choices. The first choice is to use a navigation controller (of which your initial view will have to be the root) and call
[self.navigationController pushViewController:newVC animated:YES];
The process of setting up a navigation controller correctly, etc, is nontrivial, and you should do some searching to find the best way to do that for your app. For a simple app, especially if you're just learning iOS, you can use the "Navigation-based Application" template when you create a new project. With a navcon, you get all the fancy behavior normally associated with that top bar - an automatic back button, fancy left/right scrolling when you transition to a detail view, etc.
The second option is to put a "fake" navigation bar in the detail view, using the Navigation Bar object. You can find that object, plus some other related objects, in the bottom half of the "Utilities View" (the right-most pane) in XCode. Just drag the object into your XIB and blammo, you have a 44-pixel tall gray bar. This navigation bar is just like what you get when you use a Navigation Controller except you don't get the stack functionality; you can still add buttons to the left and right, change the title, tint it to a specific color, etc.
The xib does not know you will use the controller as a modal view as it could also be used for a normal view which could show a top bar. Only when you push the view it will use or ignore the showing of this top bar.
In short: its there in case you will use the xib for a normal view :)

UINavigationController without NavigationBar

I have a "landing page/view" that I dont want the navigation bar to show, so I turn it off during the viewDidAppear
navigationBarHidden = YES;
When i push a view on the stack and then move it off. the main landing page shows the nav bar then hides it which cause a flicker that I dont want.
is there a way to have the landing page be a UIView or something? When a menu item is touched the app would push a new view on top of the default landing page. It sound like it would be hard to do without having the landing page be a UINavigationController. Any thoguhts?
Try hiding the navigation bar in viewWillAppear, rather than viewDidAppear.
If you don't need to go back to the landing page, use a view controller for the landing page and present it modally from the navigation controller when the application starts.
So you do want to go back to the landing page.
It's hard to accomplish that with UINavigationController. Suppose your are going back to the landing view. While the transition, the old view should have a navigation bar, and the new view (landing page) should not have a navigation bar. UINavigationController does not allow you manually modifying the transition animation. In other words, you cannot animate hiding/unhiding the navigation bar along with push/pop animation (using viewWillAppear doesn't solve the problem).
So what would I do, if I really, really need this?
I would have a rootViewController (of UIViewController), whose view is the only subview of your application window. When your application starts, rootViewController add the landing view as a subview of its view. When the user selects an item there, you create an UINavigationController with the corresponding view controller as its root view controller.
And, using CATransition animation with type of kCATransitionPush and subtype of kCATransitionFromRight, you add the view of the navigation controller as a subview of rootViewController's view.
Then you need a 'back' button for the first view of the navigation controller. In all view controllers that are the first level view controllers of the navigation controller, create a bar button item with a text 'Back', and add it to their navigationItem.leftBarButton property. Set a target-action (probably to the rootViewController) pair for the button.
When the action message fires, use CATransition animation (now with kCATransitionFromLeft subtype), to remove the current navigation controller's view from rootViewController's view.
The transition may not look as perfect as the native UINavigationController, but I believe this is the best you could get.
Actually the way to do this is to implement UINavigationController's delegate method navigationController:willShowViewController:animated. This method is where you should handle hiding and showing your navigation bar so the animation will occur during the push/pop animation.
I came across a method that is simple and works well for me, and is not given here yet. I assume you have a view controller for the main landing page and it is set as root view controller of the navigation controller. Then you should hide/show the navigation bar in the viewWillAppear and viewWillDisappear methods of the main landing page controller:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
Source:
http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/

Adding Navigation from home page

I'm adding navigation to subviews in my app from the home view.
I understand the concepts of pushing and popping view in the navigation stack, however, I don't want the navigation bar in the home screen.
Basically, when the user leaves the home view to any sub view, I'd like them to see the "Home" button on the left of the button nav bar, but no nav bar in the home view.
Any help would be appreciated.
It sounds like you want to start out with a bare UIViewController, containing your home screen with your own custom buttons.
The UINavigationController should come into play only when a user performs some action. Do this by
[navVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve]; // pick an effect
[self.viewController presentModalViewController:VC animated:YES];
Where navVC is the navigation controller, and self.viewController refers to your (new) main view controller. (add a suitable line IBOutlet UIViewController *viewController; + #property line + #synthesize line)
You need to fiddle a bit in the way the app starts up, for now it will probably show the navigation controller directly. If you are using a xib, you can do this by adding a UIViewController while leaving the navigation controller there as it stands. In application: didFinishLaunchingWithOptions: you'll find a line saying
[window addSubview:...];
which actually determines which viewcontroller's view is first visible. Change this to:
[window addSubview:self.viewController.view];
If you've done all this correctly, you've inserted the extra UIViewController between startup and navigation.