Watchkit , dismissController function - ios

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.

Related

How to use Modal View Controllers correctly?

I have a tabbed Iphone project in which I am attempting to present one modal segue but from multiple different view controllers.
Essentially I want it to function the same way the stock music app works in IOS 9 for iphone. You can be in any one different tab and still be able to view the account page.
Demonstration
First problem/question.
How to mimic this behavior without making a ton of segues. Currently I have 3 separate views that I want to call a modal segue from but how can I achieve this without making duplicate segues
Second problem/question.
How to dismiss the modal view without it becoming a deprecated segue. I have found tuts on how to do this but they require another segue back to the "sender" view controller.
If only apple could provide some decent sample code to aid my efforts in my attempt to do this...
you can present and dissmiss any view controller object without segue like below,
UIViewController *vc = [[UIViewController alloc]init]; // your view controller here
// You can present VC like
[self presentViewController:vc animated:YES completion:^{
// do your task on completion
}];
// In your Presented VC you can dissmiss it like
[self dismissViewControllerAnimated:YES completion:^{
//do your task on completion
}];
Update as per comment :
You can instantiate story board like,
SideMenuViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:#"sideMenu"];
Here SideMenuViewController is custom viewController class set to viewcontroller from storyboard.
And make sure you have set storyboard Id under identity from identity inspector. Here my sideMenu is storyboard Identity!
So you can instantiate your storyboard viewcontroller like this and then present it as mentioned before
Hope this will help :)

Cancel button in Navigation View not working

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...

How Can I Specify the View to Load After Form Completion in Xcode?

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];

Dismiss one modal view controller after showing another

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.

How to dismiss a view controller opened with presentModalViewController:

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.)

Resources