I need help on some logic.
This is how my application is structured.
Welcome View Controller > Login View Controller > Tab Bar Controller > Feed Navigation Controller
So, i used presentmodal for the transition of Welcome View Controller to Login View Controller.
using [self presentModalViewController:loginVC animated:YES];
So now i'm in Login View Controller. But how to i navigate to the Tab Bar Controller which will show the rootviewcontroller of the Feed Navigation Controller?
I tried [self presentModalViewController:tabBarController animated:YES];
But i'm not getting the navigation controller in it!
Thank you!
If TabBarController is your rootController, then your implementation is probably wrong.
Have the Welcome Screen as your ModalViewController and Navigate to LoginScreen, and perform necessary actions.
if (LoginSuccessful)
// Dismiss modalview controller
This will bring control back to your rootController, and you do not need to navigate from welcome to login to tab bar and stuff like that.
Related
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);
![This is My view controller connection looks][1]
http://i58.tinypic.com/2mepfv4.png
![I have to go from view controller A to VC-B through programatically, Because it should satisfy login authentication based on device ID. Let me Explain Clearly. When user installs my app he should set up his email and verify.After verification He should move to VC-B.After moving VC-B, Viewcontroller-A should not open again when he opens app again. Something like kill View controller-A, and load VC-B whenever he opens app.
Question1- How to kill View controller-A completly.
Second thing i do not want to show navigation bar On View controller-A, But on View VC-B,VC-C and VC-D so on. i want to show navigation bar because user should be able to move back and forth.That's the reason i added navigation controller before VC-B again.
If i'm not able to show Navigation bar on VC-B until i enable show navigation bar on Navigation controller before View Controller A.
Question2-How to enable Navigation bar on VC-B but not on Viewcontroller-A.
][1]
This is the code how am i moving from View controller A to VC-B.
if (alertView.tag == 99) {
if(buttonIndex == 0){
VC-B *vcb =
[self.storyboard instantiateViewControllerWithIdentifier:#"VC-B"];
[self.navigationController pushViewController:vcb animated:YES];
}
}
Help me to point Right direction.
You do not necessarily need to kill the A view controller, I do not think this is a good idea.
You can solve the issue by setting the info in NSUserDefaults when the user is successfully verified. Then navigate to the B view controller.
In the method:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
always check if that verified flag was set in NSUserDefaults, and if YES - set the rootViewController of the navigation controller to the B view controller, otherwise to the A view controller.
To hide/unhide the Nav Bar, you can do it from any view controller (assuming they belong to a navigation controller), using this code:
self.navigationController.navigationBar.hidden = YES; // or NO
This code can be written in the view controller classes, inside viewDidLoad, viewWillAppear:, viewDidAppear:, or anywhere you need.
There are also some methods if you want a nice animation for hiding/unhiding.
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.
I have a code that currently loads a NIB file like below :
Login *monLogin = [[[Login alloc] init] autorelease];
[self presentModalViewController:monLogin animated:YES];
but the app is TabBar App (xcode template) and is suppose to also load the bottom menu.
how can I load this NIB file with the UITabBarController included?
my answer to your other question might help. But now I'm a little confused about what you're attempting to do. Let me know and I can help you further.
The modal view will not include the TabBar because a TabBar owns the view controllers represented by each tab. Why do you want the TabBar included in the login view? If you really want a TabBar in your modal view, then you'll need to put your 'log in' view controller inside a TabBar view controller, and then present the TabBar view controller modally.
However, I'd recommend that you have the TabBar in the main part of your app, and present the 'log in' view modally without a TabBar included. Once the user is finished logging in, you can dismiss the 'log in' view, which returns the user to the main part of your app.
To dismiss the modal view controller, set up a delegate system (look through the utility app template to see how this works). If setting up your own delegate protocol is too difficult at the moment, then you can use a workaround in the mean time. In your 'log in' view controller code, after the user has logged in successfully, you can send a message to your parent view controller (the one that presented the modal view) to dismiss it's modal view (your 'log in' view).
[self.parentViewController dismissModalViewControllerAnimated:YES];
This is bad form though. Once you're up to it you should use a delegate callback to have the parent view controller dismiss the modal view.
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/