I want a viewcontroller to launch using a show transition, not modally from the bottom. Normally when I use the following code that's what happens. However, in this case, it is launching as a modal controller from the bottom up. Is there a switch I don't know about or could something be set in Storyboard that is causing this VC to launch modally from the bottom instead of showing?
UIStoryboard *storyBoard = self.storyboard;
IDImportEventsOnboard *importEvents =
[storyBoard instantiateViewControllerWithIdentifier:#"importEventsOnboard"];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController: importEvents];
[self presentViewController:nav animated:YES completion: nil];
The VC is embedded in a navigation controller.
Should I be using showViewController directly to the targetVC without going through the Nav? Or a pushViewController What is a proper, robust way to show a VC with a show transition?
Thanks in advance for any suggestions.
In the above code you are 'presenting' a new NavigationController from a ViewController. In order to do a push/show transition, that needs to be done on an instance of a NavigationController. If your current ViewController is already in a NavigationController, you can push the new ViewController onto the current NavigationController stack. For Example:
UIStoryboard *storyBoard = self.storyboard;
IDImportEventsOnboard *importEventsVC =
[storyBoard instantiateViewControllerWithIdentifier:#"importEventsOnboard"];
[self.navigationController pushViewController:importEventsVC animated:YES];
Related
I have two profile in my app. So after some initial profile setup, my app will start with different screens (firstVC or SecondVC).
So based on the initial (Consider Appdelegate :didfinish Method) setup, i wish to select "sw_front" to be firstVC or secondVC.
Every time firstVC is loaded first. If i wish to open SecondVC first, i tried is very simlpe code in viewWillAppear Method, may be incorrect:
UIViewController * sec = [self.storyboard instantiateViewControllerWithIdentifier:#"SecondID"];
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:sec];
[self.revealViewController pushFrontViewController:nav animated:YES];
The issue is app directly enters firstVC, but I want it to enter directly in FirstVC or SecondVC, when needed.
Thanks, any help appreciated :)
May be you are coding wrong.Try below code when you are pushing.
UIStoryboard *storyboard = nil;
storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:nil];
SWRevealViewController *vc = [storyboard instantiateViewControllerWithIdentifier:#"SecondID"];
[self.navigationController pushViewController:vc animated:YES];
This is how I am pushing a UIViewController :
[tabController setSelectedIndex:0];
UINavigationController *navController = [tabController selectedViewController];
UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:#"Main" bundle: nil];
NotificationViewController *notificationController = (NotificationViewController*)[mainStoryboard
instantiateViewControllerWithIdentifier: #"NotificationViewController"];
[navController pushViewController:notificationController animated:YES];
navController.navigationBarHidden = NO;
When NotificationViewController is visible and I tap Back button, nothing happens. The previous UIViewController had a gesture in UINavigationBar but I have removed it in the UIViewController's viewWillDisappear. But still the NotificationViewController's Back button doesn't work.
You probably call the pushViewController before the view is visible.
Make sure you don't call your pushViewController in the viewDidLoad.
Your pushViewController should be used only after viewDidAppear is called if you want your navigation controller to work properly with the back button. Otherwise, the navigation controller will add the title to the previous view controller without the redirection link.
I want to push to a new viewcontroller from a presented viewcontroller. I don't want to dismiss the presented viewcontroller. I want the new viewcontroller to come over the presented viewcontroller.
Can anybody tell me how to do that.
You do not push form the presented controller so the best option is
First you have to dismiss the controller without animation and then in the method of -(void)viewWillApper you can easly push to the controller where you want to push.
You can do by using UINavigationController like
UINavigationController *vcObject = [[UIStoryboard storyboardWithName:#"Main" bundle:nil] instantiateViewControllerWithIdentifier:#"YourViewController"];
[self.navigationController presentViewController:vcObject animated:YES completion:NULL];
Now you can easily push or pop to other ViewController like you want.Thankyou
Open your modalView controller as a new rootViewController :
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController:nextViewController];
[self.navigationController presentViewController: navController animated:YES completion:nil]
In my AppDelegate I have the following code which is executed after receiving a notification:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *navigationController = (UINavigationController *)[storyboard instantiateViewControllerWithIdentifier:#"VideoPlayback"];
VideoPlaybackViewController *videoPlaybackViewController = (VideoPlaybackViewController *)[navigationController topViewController];
videoPlaybackViewController.publishing = YES;
[(UINavigationController*)self.window.rootViewController pushViewController:navigationController animated:NO];
That successfully brings up the new ViewController and apparently adds it to the navigation stack, since I can use the back button on the navigation bar to go back and subsequently dismiss the view controller.
The problem is, I don't want to use the navigation bar. In fact, I would like to hide the back button. Unfortunately, when I try to dismiss the viewcontroller using the method(s) it should use, it does nothing. I've tried using both of these to dismiss the view controller:
[self dismissViewControllerAnimated:YES completion:nil];
[self.navigationController popViewControllerAnimated:YES];
What am I doing wrong? Thanks.
You're trying to push a navigation controller into a navigation controller, which won't end well.
[(UINavigationController*)self.window.rootViewController pushViewController:navigationController animated:NO];
probably needs to be changed to:
[(UINavigationController*)self.window.rootViewController pushViewController:videoPlaybackViewController animated:NO];
I am developing an app that use MFsidemenu for the swipeBar.
My app consists of a loginController which is an uiViewController and after logging it change into an uiNavigationController.
MFsidemenu need this code running on the AppDelegate:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboard" bundle:[NSBundle mainBundle]];
UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
UIViewController *leftSideMenuViewController = [storyboard instantiateViewControllerWithIdentifier:#"leftSideMenuViewController"];
[MFSideMenu menuWithNavigationController:navigationController
leftSideMenuController:leftSideMenuViewController
rightSideMenuController:nil];
The problem is how to change the second line of the code if the initialView is an uiViewController(Login) and after that, how to pass it to the secondViewController(MainMenu) which is an uiNavigationController?
In a shortway, I want the MFSidemenu to work only on the secondController, which is the main controller. Thanks!
Updated:
solved, by SpaceDust solution below :)
Question Update:
So the example of using MFSidemenu only limited to showing a sidemenu on the controller. The example sideMenuController exiled from any other segue on the storyboard. on the sidemenu I implemented uiTableViewController to navigate to another controller. So how to change MainMenuView with sideMenuController didSelectRowAtIndexPath? I hope my english good enough to represent my situation though. Thanks once again!
You need to present your uiViewController(Login) as a modal view controller if you dont want to side menu appear during login.
Create a login viewcontroller in storyboard, give it a storyboard id lets say LoginViewController . Dont connect that viewcontroller to anything on storyboard let it sit a corner by itself.
first create a global singleton variable where you check if user is logged in
then In your navigationcontroller's rootviewcontroller
-(void)viewWillAppear:(BOOL)animated
{
//this will present the login view if user is not logged in
if (isLoggedIn==NO) {
UIStoryboard* sb = [UIStoryboard storyboardWithName:#"MainStoryboard"
bundle:nil];
LoginViewController *loginVC = [sb instantiateViewControllerWithIdentifier:#"LoginViewController"];
[self presentModalViewController:loginVC animated:YES];
}
}
in your login viewcontroller when login process is complete
change global singleton bool to isLoggedIn=YES
then dismiss your login view controller.
[self dismissViewControllerAnimated:NO];