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.
Related
![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.
I created a new navigation controller in my storyboard (not programmatically!) and set it to be "Root View Controller" to a regular UIViewController and added a button in it which says- forward to the next view controller (this second view controller is a view controller which I want that will have a back button to link to the initial view controller).
Now, whenever I try to link the button to the next view controller- "Pushing a navigation controller is not supported".
Help me please, and thanks
EDIT:
I accidentally subclassed UINavigationController, and not UIViewController in my class.
Thank you anyway.
I've tried this and have no problems, its all done in IB with no additional code required ...
Start a new project, "Single View Application" using story boards
Select storyboard and delete the views its produced.
Drag on a new Navigation Controller (it will bring a table view with it)
Delete the table and the table view controller, so you are just left with the Navigation Controller
Drag on a normal view controller
Right Click and drag from the Navigation controller to the new View and choose "Relationship - Root View Controller"
Drag a "Bar Button Item" on to the Navbar which should be visible on the top of your ViewController, you can rename this Forward if you wish.
Now drag on another view controller which is the one your "Forward" button will push in to view.
Right Click and drag from the bar button to the 2nd View Controller, and choose "Push"
Run the project and you will get a Single view with a Navbar and your button, clicking your button will Push the other view and give you a Back Button to return to the first View Controller. I'll try and post a picture of my storyboard if it helps.
Plasma
I had the same trouble. I wanted to have a navigation controller on each storyboard, so that each could run independently, be individually debugged, and so that the look would be right with the navigation bar.
Using other approaches, I found the UINavigationController would be retained from the original storyboard -- which I didn't want -- or I'd get errors.
Using the AppDelegate in your view controller to set the rootViewController worked for me (borrowing segue naming conventions from Segue to another storyboard?):
- (void)showStartupNavigationController {
NSLog(#"-- Loading storyboard --");
//Get the storyboard from the main bundle.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:#"Startup" bundle:nil];
//The navigation controller, not the view controller, is marked as the initial scene.
UINavigationController *theInitialViewController = [storyBoard instantiateInitialViewController];
NSLog(#"-- Loading storyboard -- Nav controller: %#", theInitialViewController);
//Remove the current navigation controller.
[self.navigationController.view removeFromSuperview];
UIWindow *window = [(AppDelegate *)[[UIApplication sharedApplication] delegate] window];
window.rootViewController = theInitialViewController;
To swap views Programatically you would need to select the segue and give it an Identifier like "PushView" then call it like this ....
[self performSegueWithIdentifier:#"PushView" sender:self];
That will programatically do the same as clicking the forward button. I've created you an example project with the code discussed above. Has an -(IBAction) with code in you can use for programatially changing the view.
PushView.zip
I also wanted to do this, present a screen (that had an embedded navigation controller) when the user pushes a button.
At my first attempt, I connected the segue from the button in the fist screen to the Navigation Controller, and the app was crashing with this error "Pushing a navigation controller is not supported".
This is the solution I found:
Select the segue from the button in the first screen to the navigation controller.
If it had an identifier, copy its name. Then delete that segue.
Then create a new segue by CTRL-clicking the button in the first view controller and dragging to the VIEW CONTROLLER YOU WANT TO PRESENT (not to the Navigation Controller that is pointing at it), and select Push in the small pop up window.
Then click the icon in the middle of the segue and paste the name you copied in the first step as an identifier for it.
IB is going to give you a warning "Scene is unreachable due to lack of entry points and does not have an identifier for runtime access via -instantiateViewControllerWithIdentifier:." Don't worry, it works perfectly.
If you want to customize the string that is shown as the Back button to return, you can add this line in the viewDidLoad method OF THE VIEW CONTROLLER THAT IS BEING SHOWED AFTER THE BUTTON IS PRESSED, that is the Child view controller.
(replace "Settings" with the name you need)
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.topItem.title = #"Settings";
...
}
i want to dismiss my current view controller then load up a new view controller. this seems like it should work:
FieldReportViewController *fieldReport = [self.storyboard instantiateViewControllerWithIdentifier:#"fieldReportView"];
[self presentModalViewController:fieldReport animated:YES];
[self dismissModalViewControllerAnimated:NO];
i present the new modal, then dimiss the old one. but the old one doesn't actually get dismissed.
any idea how i can get this done or why this won't work?
You are not dismissing the old modal view controller....you are dismissing the new one you just presented. Try dismissing the modal view controller first.
first dismiss the old view before present the nezt one or use the actual names instead of "self"
add this code:
#import "class of the to dismiss view.h"
#class class of the to dismiss view
When you present a modal view controller, depending on which iOS version you're using, you're setting the property modalViewController or presentingViewController of the 1st modal to a second modal and adding the 2nd view controller to the view hierarchy. If you were successful in removing the first modal, the second modal would no longer be attached to any view hierarchy.
What you may want to consider is using a single view controller and just replacing the view for that modal view. I think this would give you what you want.
Alternatively, you should probably dismiss the first modal and from the previous view controller present the second modal.
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.
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/