I'm developing an application, and at some point I need a Modal ViewController to "become" the Root ViewController.
How can I dismiss the current rootController, and set my Modal as my new rootController?
First you have to set your root view controller nil.
[self.window setRootViewController:nil];
UIStoryboard *MainStoryboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle: nil];
Nearbylocations *introViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"near"];
self.window.rootViewController=introViewController;
You can try below code..
[self dismissViewControllerAnimated:NO completion:nil];
UINavigationController *navBar=[[UINavigationController alloc]initWithRootViewController:modalviewref];
[self.navigationController presentViewController:navBar animated:YES completion:nil];
Hope it helps you..!
Related
I'm trying to call a controller, if has response error, and redirect the user for login controller.
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"EventManagerStoryboard" bundle:[NSBundle mainBundle]];
LoginViewController *loginController = [storyboard instantiateViewControllerWithIdentifier:#"loginID"];
[loginController viewDidLoad];
loginController.showOnlyLoginForm = YES;
[self presentViewController:loginController animated:YES completion:Nil];
and I facing this warning -
Attempt to present Attempt to present LoginViewController: 0x7fc958201130 on ProfileController: 0x7fc9583118e0 whose view is not in the window hierarchy!
Don't run this code in viewDidLoad try it in viewDidAppear
[self presentViewController:loginController animated:YES completion:Nil];
Edit:
use in appDelegate if you implement navigationController
[(UINavigationController *)self.window.rootViewController pushViewController:vc animated:YES];
I have 5 view controller and want to come back from the last view to 1st view controller
Call a function in which you have to change the app rootviewcontroller. set it as a navigationController
yourViewcontoller *viewController = [[yourViewContoller alloc] init];
UINavigationController *navController=[[UINavigationController alloc]initWithRootViewController:viewController];
self.window.rootViewController = navController;
If you're using storyboards, give the UINavigationController a Storyboard ID. You can then initiate it and present through the code:
UINavigationController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"<Storyboard ID>"];
[self presentViewController:vc animated:YES completion:nil];
Use this method on Animation splash screen
[self performSelector:#selector(setHidden:) withObject:nil afterDelay:2.0];
-(void) setHidden:(id)sender
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"MainStoryboare" bundle:nil];
YourVC* vController = (YourVC*)[Storyboard instantiateViewControllerWithIdentifier:#"storyboardId"];
UINavigationController *navcotoller=[[UINavigationController alloc]initWithRootViewController:vController];
self.window.rootViewController =navcotoller;
}
If you are using UINavigationController you could and should simply call
[self.navigationController popToRootViewControllerAnimated:YES];
I am tring to show UIViewController which is inside the UIStoryboard. There isn't any problem about poping up the view. But the navigation is not working in the popup viewcontroller; such as when I touch back button
[self.navigationController popViewControllerAnimated:YES];
I am using that code in AppDelegate --> didReceiveRemoteNotification method
UIStoryboard *mystoryboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
PFProfileInfoVC *viewcontroller = [mystoryboard instantiateViewControllerWithIdentifier:#"SBID_ProfileVC"];
viewcontroller.strAuthorID = [userInfo objectForKey:#"aps"][#"targetId"];
[self.window.rootViewController presentViewController:viewcontroller animated:YES completion:nil];
Thanks,
When you use presentViewController, the viewController is not pushed onto the navigation stack. Normally, it is presented modally. So if you want to dismiss it, use
[self dismissViewControllerAnimated:true completion:nil];
Hi, this is my storyboard , i wanna go from First view controller to LoggedinViewController.
Im normally using
[self performSegueWithIdentifier:#"s1" sender:self];
but if i add tab bar controller this line is not working , how can i fix this ?
You can use the following if you have embedded into navigation controller.
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:#"Story_Board_Name" bundle:nil];
UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:#"TABid"];
self.tabBarController.selectedIndex = 0;
[self.navigationController pushViewController:self.tabBarController animated:YES];
Or try this
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:#"Story_Board_Name" bundle:nil];
UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:#"TABid"];
self.tabBarController.selectedIndex = 0;
[self performSegueWithIdentifier:#"s1" sender:self];
Give your tabbarcontroller an identifier from the storyboard, the do something like this
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:#"Your_Story_Board_Name" bundle:nil];
TabViewController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:#"TAB_Identifier"];
[self presentViewController:tabBarController animated:YES completion:nil];
Hope this helps
first give "tabbarid" to that tab inside storyboard
UITabBarController *tabBarController1 = [self.storyboard instantiateViewControllerWithIdentifier:#"tabbarid"];
tabBarController1.selectedIndex = 1;
[self presentViewController:tabBarController1 animated:YES completion:nil];
In MyMainViewController, I present a navigation controller like this:
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:#"Main_iPhone" bundle:nil];
UINavigationController* nc = [storyboard instantiateViewControllerWithIdentifier:#"NAVIGATION_CONTROLLER_ID"];
[self presentViewController:nc animated:YES completion:nil];
Later, from somewhere within the view hierarchy of the UINavigationController, I need to return to MyMainViewController. How can I do this?
(Note: MyMainViewController is defined in a .XIB, and not in the storyboard where the UINavigationController and it's children are defined.)
It sounds like you have modally presented a NavController that you want to remove. Modally presented VC's can remove themselves.
Somewhere in your NavController add:
[self dismissViewControllerAnimated:YES completion:^{
NSLog(#"Dismissed nav controller modally");
}]
[self.navigationController popToViewController:[[self.navigationController viewControllers] objectAtIndex:2] animated:YES];
I gues you know the index of your view controller. If you simply want to return to the rootViewController you can do it like
[self.navigationController popToRootViewControllerAnimated:YES];
If you want to push new viewController to the navigation stack just do it like
MyMainViewController *mainController = [[MyMainViewController alloc] initWithNibName:#"MyMainViewController" bundle:nil];
[self.navigationController pushViewController:desController animated:YES];
Returning to the previous viewController would be
[self dismissViewControllerAnimated:YES completion:nil];