I have a code like this to present a TOWebViewController that contain URL to my company web page.
TOWebViewController *webViewController = [[TOWebViewController alloc] initWithURL:url];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:webViewController];
[[[[UIApplication sharedApplication] delegate] window] setRootViewController:navigationController];
After its open how I get back to my previous view or dismiss the root view controller since my navigator bar only show grey bar.
thanks
Use [self presentViewController:imagePickerController animated:YES completion:nil]; instead.And don't use root view controller!
you need to create a custom back button #selector and in it you need to set [[[[UIApplication sharedApplication] delegate] window] setRootViewController:previousViewController];
though you need the reference of your previous viewController, however i won't recommend this approach.As #lumialxk said, use this instead [self presentViewController:imagePickerController animated:YES completion:nil];
Related
My UIViewController stack looks as follows:
+------ UIViewController_C (presented)
+---- UIViewController_B (presented)
+-- UIViewController_A (pushed)
When I call -dismissViewController:animated on UIViewController_C, UINavigationController dismisses both UIViewController_C and UIViewController_B together, as per the docs with animation on _C, and none on _B.
What is the most compliant way to dismiss _C only?
try as below
after pushing to UIViewController_A present UIViewController_B as below code.
UIViewController_B *bbp=[[UIViewController_B alloc]initWithNibName:#"UIViewController_B" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
passcodeNavigationController.navigationBar.hidden=YES;
[self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];
now from UIViewController_B try to present in UIViewController_C as below code.
UIViewController_C *bbp=[[UIViewController_C alloc]initWithNibName:#"UIViewController_C" bundle:nil];
UINavigationController *passcodeNavigationController = [[UINavigationController alloc] initWithRootViewController:bbp];
passcodeNavigationController.navigationBar.hidden=YES;
[self.navigationController presentModalViewController:passcodeNavigationController animated:YES];
[passcodeNavigationController release];
last and final thing on every back button of view controller write below line of code.
[self dismissModalViewControllerAnimated:YES];
if you want more help than comment bellow.
One Solution:
UIViewControllers presented modally are not necessarily deallocated on -dismissViewController:animated.
This means that by passing a reference to UIViewController_A through _B to _C, you can call -presentViewController:animated and -dismissViewController:animated for the respective UIViewControllers via UIViewController_A.
Code:
1. UIViewController_B
- (void) showUIViewController_C {
[self dismissViewControllerAnimated:TRUE completion:^{
UIViewController_C *controller_C = [[UIViewController_C alloc] init];
controller_C.parentController = self;
[self.parentController controller_C animated:TRUE completion:nil];
}];
}
2. UIViewController_C
- (void) dismissUIViewController_C {
[self dismissViewControllerAnimated:TRUE completion:^{
[self.parentController.parentController presentViewController:self.parentController animated:TRUE completion:nil];
}];
}
Where I am using *parentController as the naming convention for whatever class your previous UIViewController on the stack may be.
It dips back to UIViewController_A briefly because I am calling -dismiss and -present in the completion block, though that actually looks rather fun.
I'm attempting to present a view controller from the app delegate with this code:
- (void)interstitialViewControllerRequestSucceeded:(UIViewController *)interstitialViewController
{
[self.window.rootViewController presentViewController:(UIViewController *)interstitialViewController animated:YES completion:NULL];
}
It will display the interstitial on the initial view controller but none of the others. I want it to display on every one attached to a navigation controller.
How can I modify this code to achieve that goal?
You can also try:
[[[UIApplication sharedApplication] keyWindow] rootViewController]
How I use it:
#define ROOTVIEW [[[UIApplication sharedApplication] keyWindow] rootViewController]
[ROOTVIEW presentViewController:interstitialViewController animated:YES completion:^{}];
Swift 3 version for checked response :
UIApplication.shared.keyWindow?.rootViewController
Swift 5 and up
Check this:
UIApplication.shared.windows.first?.rootViewController
Currently, when a button is tapped, a UIModalPresentationSheet comes up. I'd like to add a navigation bar at the top of this when it slides up. I've tried a lot of things but nothing seems to work. Here's what i'm currently trying and it returns this error.
AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:#"addAthlete"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
//[self.navigationController pushViewController:addAthlete animated:YES];
addAthlete.delegate = self;
addAthlete.modalPresentationStyle = UIModalPresentationFormSheet;
// UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
[self presentViewController:navigationController animated:YES completion:nil];
But it pushes it up modally, and without the modalpresentationsheet form. How can I make it so the navigation controller is sized correctly?
Try to change your code like this :
AthleteAdd *addAthlete = [self.storyboard instantiateViewControllerWithIdentifier:#"addAthlete"];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addAthlete];
addAthlete.delegate = self;
navigationController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:navigationController animated:YES completion:nil];
Because here, you try to present addAthlete from itself. So you get this error.
You should present navigationController in which you encased your addAthlete.
[self presentViewController:navigationController animated:YES completion:nil];
You are presenting from current viewcontroller itself.
Try something like,
[self dismissViewControllerAnimated:YES completion:^{
[self.parentViewController presentViewController: navigationController animated:YES completion:nil];
}];
If i use
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[self presentViewController:ngView animated:NO completion:nil];
above code the controller will go to NGViewController page.
But if I use this navigation controller
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[self.navigationController pushViewController:ngView animated:YES];
the Controller will be in same page.
Can any one tell that what's the problem.
You should use this code
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[self presentViewController:ngView animated:NO completion:nil];
after writting this line when then you you want go on different page with push view controller
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:ngView];
[self.navigationController pushViewController:navigationController animated:YES];
I hope you will solve this issue by this code Good luck
Your self.navigationController is probably nil - check it out through debugging. Your self view controller is not within a UINavigationController.
Now i m using this code
NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.50];
[self presentViewController:ngView animated:NO completion:nil];
so that it wil give same effect other
Self Controller should have navigation controller (in Storyboard) in order to navigate.
[self.navigationController pushViewController:nextController animated:YES];
UINavigationController is a controller of controllers and it is designed to allow you to push and pop controllers and manage a hierarchy of your view's. And your navigationController property tells you whether your NGViewController is currently in a UINavigationController's hierarchy; if not (as in this case), the navigationController property returns nil.
You have to create your own navigation controller and then try to push the view controllers and thus build up a view hierarchy.
I normally would suggest this:
UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:firstviewController];
[self.window setRootViewController:navigationController];
navigationController.delegate = self;
navigationController.navigationBarHidden = YES;
you need to declare this in your first controller
NGViewController *ngView = [[NGViewController alloc]init];
[self.navigationController pushViewController:ngView animated:YES];
I have a main view controller and am presenting a child view. For one of the settings inside the child, I need to call the main view controller again. It would just make things a lot easier.
The following causes a hierarchy problem:
#define appDelegate (MyAppDelegate *)[[UIApplication sharedApplication] delegate]
[self presentViewController:[appDelegate mainViewController] animated:YES completion:^{}];
Is there any way to call the mainViewController easily while not losing the state of the child view?
EDIT
Here is how I'm presenting the child view.
ChildViewController *childViewController = [[ChildViewController alloc] init];
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:childViewController];
[childViewController release];
[self presentModalViewController:navigationController animated:NO];
[navigationController release];
You can't present a view controller that has already been presented or is in a navigation stack. What is the mainViewController? Did you instantiate it? Has it been added to the screen yet?
If yes to both, you either need to back into it (dismiss to it) or remove it from it's parent first and then present it.
In your child view, you should have access to your application delegate and its mainViewController property, like this:
MyApplicationDelegate *appDelegate = (MyApplicationDelegate *)[[UIApplication sharedApplication] delegate];