how to dismiss a modal viewcontroller in iOS6 [duplicate] - modal-dialog

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
dismissModalViewControllerAnimated deprecated
I have 2 view controllers, one being a game and the second simply being an "About" screen. When someone goes to the about screen - presented as a modal view controller - how can I have them dismiss the view controller to get back to the first screen?
I can do this with a push segue, but that causes my game to "reload".
THe following code appears to work, but XCode warns that it is deprecated.
[self dismissModalViewControllerAnimated:YES];
What is the new way to do this?
Thanks,

Try this
[self dismissViewControllerAnimated:YES completion:nil];

Related

Xcode sub navigation views

Does anyone know of any good tutorials for the following please?
Im new to Xcode and dont know where to start with this.
I have a ViewController that is the root View and has 6 navigation buttons (UIButton) on it. Depending on which button that is clicked, the user will see a sub-navigation View of that section with further button options on it.
So e.g top level will have buttons Where to Eat, What to Do...
Then clicking on Where to Eat will show Restaurants, Fast Food ....etc
I would like to do this programatically. I can do it using Storyboards and using multiple views, but it gets very messy as there are a lot of views on the screen eventually.
I have followed a tutorial HERE on how it is done for TableViewControllers, but I need something similar for buttons.
Im not sure what this function is called - have been searching for sub-navigation for the last while but nothing matches what I need to accomplish this.
Check out UIViewController's method presentViewController:animated:completion: method. It is available in iOS 5.0 and up. Let's say you have one of the button's linked to run the buttonOneActivated: method:
-(IBAction)buttonOneActivated:(id)sender
{
UISubViewController *subViewController = [[UISubViewController alloc] init];
[self presentViewController:subViewController
animated:YES
completion:NULL];
}
And in UISubViewController's implementation, let's say you have another button in order to return to the parent:
-(IBAction)returnToParent:(id)sender
{
[[self presentingViewController] dismissViewControllerAnimated:YES
completion:NULL];
}

UINavigationController - implementing back to beginning button [duplicate]

This question already has an answer here:
popping to root view in navigation controller
(1 answer)
Closed 8 years ago.
I have a UINavigationController which has several screens that implement a logical set of stepped tasks ...
Is there a way that on the last screen I can have logic on a done button that would take me to the start without having to step back through the screens ?
I am really looking for code examples of the logic I would need to put on the done button?
Many thanks
You have to pop directly to rootview controller instead of just popping.
use:
[self.navigationController popToRootViewControllerAnimated:YES];
use this
[self.navigationController popToRootViewControllerAnimated:YES];
You have two options to achieve this thing on DONE button ;
1) If your rootview is the view from where you want to restart than you can use as follows -
[self.navigationController popToRootViewControllerAnimated:YES];
2) Else you can re-initialize the navigation Controller & push to the start view.
Hope this will help.
popToRootViewControllerAnimated -> It will pops all the view controllers on the stack except the root view controller and updates the display.
[yourNavigationController popToRootViewControllerAnimated:YES];
If you want to use popToViewController then
id rootView=[[self.navigationController viewControllers] objectAtIndex:0];
[self.navigationController popToViewController:rootView animated:YES];

dismissModalViewControllerAnimated crashing on iOS6

I am facing a crash on iOS 6.0. I have a view controller from which I present a navigation view controller modally and then from the navigation stack I present another view controller modally and finally to dismiss the whole modal stack I pass the following message to my first view controller from where I showed the navigation controller.
Now this works fine on iOS below 6.0. How should I handle this?
[self dismissModalViewControllerAnimated:YES];
I had this similar crash as well and one of the things helped me solve it was adding:
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
maybe because dismissModalViewController is deprecated in iOS6? Try
[self dismissViewControllerAnimated:YES completion:nil];
EDIT: Lets say you add a method to appDelegate called 'makeMeNumberOne:(UIViewController *)vc':
(I know you use the 'modal' versions, they are deprecated in iOS6, switch to 'presented' variants)
. Also I assume you can find the navigationController, if this is a problem add a comment I'll further expand this, and assume you are using ARC.)
the parameter you have is a strong reference, it holds the current presented viewController, lets call it pvc
ask the navigationController for its viewControllers, and get the last one
as a debugging tool, verify that this vc has a non-nil presentedViewController property
message the last view controller above:
[lastOne dismissViewControllerAnimated:NO completion:^{
[navigationController.viewControllers = #[pvc];
}];

Navigating through UIVIewControllers [duplicate]

This question already has answers here:
A home button in iOS 5, xcode 4.2, Story board
(2 answers)
Closed 8 years ago.
From the FirstView to the SecondView i will be navigating through pushViewController.
In the SecondView there's a button, when i click that i will be calling another view which is called ThirdView, and i will be navigating through presentModalViewController animated:YES.
I need a code, to go from the ThirdViewController to FirstViewController, How can i do that ?
I have not tried any code, because i am clueless as what to do
You can use delegate to move back to the first view controller... On cancel button in the THIRD, delegate some method to the SECOND, where you:
1) [self dismissModalViewControllerAnimated:YES];
and
2) [[self navigationController] popViewControllerAnimated:NO];
FIRST would be active as a result
I flagged as a duplicate but you are getting a lot of misleading answers here, so I'll re-post my answer from the other question:
popToRootViewControllerAnimated: on UINavigationController will clear out the stack and return you to the root controller. There is no need to individually dismiss each controller in the stack.
In your second view controller add method like
-(void)goToFirstViewController{
[self.navigationController popViewControllerAnimated:NO];
}
In third View controller
UIViewController *secondVC = [self parentViewController];
// If you use ios 5 do [[self presentingViewController] popViewController];
[secondVC goToFirstViewController];
[self dismissModalViewController];

Automatically dismiss underling modal view

I'm sharing this as it took me A while to figure out. This is if you need to get rid of a double stack of modal views IF it is pressent.
if(self.parentViewController.parentViewController)
[self.parentViewController.parentViewController dismissModalViewControllerAnimated:YES];
else
[self dismissModalViewControllerAnimated:YES];
I have a view that sometimes gets called from a modal view. In that case I would need to get rid of both views at the same time. While dealing with the situation where it was the only modal view. This worked.
As of xCode 4.2 this is no longer working, The new way to deal with this situation is:
if(self.presentingViewController.presentingViewController)
[self.presentingViewController.presentingViewController dismissModalViewControllerAnimated:YES];
else
[self dismissModalViewControllerAnimated:YES];
As pointed out by #Hollance in a relevant thread of mine:
iOS 5 SDK treating UIViews differently
"There is a new property in iOS 5 named presentingViewController. The meaning of parentViewController got changed a bit with the new container view controller API, so it may not always be set when you think it is. That's what presentingViewController is now for."