I presented a view controller using presentModalViewController:, now how to close/dismiss it?
For iOS6 use this code
[self dismissViewControllerAnimated:YES completion:Nil];
instead of
[self dismissModalViewControllerAnimated:YES];
This may help you.
From the controller presented modally:
[self dismissModalViewControllerAnimated:YES]
You have two choices, both involves using dismissModalViewController.
The preferred way is to use delegation and tell the view controller who was responsible for presenting the view to dismiss it. The other way is to have the view who was presented to dismiss itself (which actually asks the parent to dismiss it.)
Related
code for cancel button is
- (IBAction)cancelButton:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
While tracing the program I can see the method is called however the view is not dissmissing to the previous view controller.
if you use Navigation View controller you should use
[self.navigationController popViewControllerAnimated:YES];
instead of dismissViewControllerAnimated
PS actually, I think you use storyboards and segues and in this case you should use UnwindSegue What are Unwind segues for and how do you use them?
Also you should read some common documentation about in app navigation...
i want to push in another view controller with code
[self pushControllerWithName:#"secondeviewcontroller" context:#"Hello"];
its work great for pushing but for dissmiss
in secondviewcontroller doesn't work
[self dismissController];
In a hierarchical interface, you need to to use [self popController] to go back after pushing a controller.
[self dismissController] is used in modal interfaces.
I currently have a main web view (UIViewController) that presents a UIViewController like this:
[self presentViewController:controller animated:YES completion:nil];
I am trying to observe when the presented view controller gets dismissed using:
[self dismissViewControllerAnimated:YES completion:nil];
I have tried observing a variable in the main web view that the presented view sets when it's being dismissed, but that doesn't seem to work.
How would I go about observing when the presented view gets dismissed?
Any help would be appreciated.
Thanks.
Can you put some code in the viewWillDisappear method? You're not clear on why you actually want to observe the variable. However this method will be called just before the view moves off. Conversely you can run code in the viewDidDisappear which is run after the view pops.
Currently I have the following code which send the user back to the last active view:
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
After researching presentingViewController I see that is what is causing this view to load. Rather than sending the user to the last active view, I would like to specify the view where they will be redirected. There must be a simple way to adjust this, if so what is it?
It would make much more sense to use a navigation stack for your needs. Instead of presenting this "form" with presentViewController:, embed your view controller within a navigation controller and use:
[self.navigationController pushViewController:theForm animated:YES];
Afterwards, push the next controller onto the stack:
[self.navigationController pushViewController:nextController animated:YES];
I've done a bit of research and read other answers I found here but haven't found anything that actually works. I have an app that when something is posted I want to go to the post and if the back button is pressed when viewing the post it should go back two views basically skip over the compose view.
Below is what I've tried but it gives
Warning: Attempt to present on whose view is not in the window hierarchy!
-(IBAction)post{
[[self presentingViewController] dismissModalViewControllerAnimated:NO];
}
-(void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:animated];
ViewPostViewController *dvController = [[ViewPostViewController alloc] initWithNibName:#"ViewPostViewController" bundle:[NSBundle mainBundle]];
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:dvController];
nc.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:nc animated:NO];
[nc release];
}
If you trying to create a hierarchy of views like this, you should probably be using these:
[self.navigationController pushViewController:ViewController animated:BOOL completion:nil];
[self.navigationController popViewControllerAnimated:BOOL completion:nil];
Instead of:
[self presentViewController:ViewController animated:BOOL completion:nil];
[self dimissViewControllerAnimated:BOOL completion:nil];
PresentViewController is usually used to show a single view controller then dismiss it, not generally when you want to show several view controllers in a chain, then work your way back up the chain.
The former is advisable because it uses the stack concept to push and pop view controllers. So you can start with your initial list set up as the root view controller, push on your post compose view, then push on the third view to go to posting. Then when you want to go back to the first view controller by popping off two view controllers, you can use:
[self popToRootViewControllerAnimated:BOOL completion:nil];
You might find the UINavigationController reference useful.
Good luck.
If you want to present a view controller right after another modal view controller has animated out then you have to delay it because otherwise the new one will not appear.
before iOS 5 you would do a performSelectorAfterDelay: with something like 0.25 sec. For iOS 5 and above you wouldn't use modelViewController methods any more as those have been deprecated. Instead you use the presentViewController methods which give you an completion block that is called when the animation is done.
I'm a little confused about what you're trying to do. If you're using a navigation controller, you should be doing pushes and pops, not presenting and dismissing. If you want to use navigation controllers, then you can use popToViewController:animated: to go back to any particular controller without passing through the ones in between. You would have to create a custom back button, though, or do it in code, because the standard back button will only take you back to the previous view controller.