Dismiss two modal view controllers with one animation - animation

I have a the following view controller stack:
A -> B (presented modally) -> C (presented modally).
My objective is to dismiss C and B AND the animation I want is that C slides down to reveal A.
With both answers listed here below, the animation you'll see is that C disappears and the B slides down -- which is not the desired animation.
Dismiss two modal view controllers
How to Dismiss 2 Modal View Controllers in Succession?

Have you try:
ViewController1.dismissViewControllerAnimated(true, completion: nil)
ViewController2.dismissViewControllerAnimated(true, completion: nil)
by default, the animation is "slide down", otherwise you can customize to however you want.

Related

How to change the segue type of the storyboards

I've got this problem. I want the view controller to change when the player presses a specific button.
So I added a new "view controller" in the main storyboard, I customised it and then, holding the right button of the mouse, I dragged the button on the new view controller.
It appeared a little menu with different items:
show
show detail
present modally
present as a popover
custom
I've tried all of them, nothing changed (except for the last one: the app crashes).
The new view controller is like a moving window, if you swipe down you go back to the start menu.
What I want is that the new window replaces the first one.
Here's the problem
As you can see, the brown window is movable
As I understand you need to present view controller full screen.
You need to select "present modally" segue type. Then select segue in storyboard
And then select presentation style "Full screen"
Or you can make this programmatically:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nextVC = storyboard.instantiateViewController(withIdentifier: "nextVC") as! NextVCClass
nextVC.modalPresentationStyle = .fullScreen
self.present(nextVC, animated: true)

unwind segue vs. popViewControllerAnimated

I have a mapview that is connected to several viewControllers.
I needed to implement an 'unwind' from another button (as opposed to just the back button), so I used:
self.navigationController?.popViewControllerAnimated(true)
My question is: as the above works, should I even bother trying to implement unwind in code using prepareForUnwind and canPerformUnwindSegueAction in the parent view controller + ctrl-drag from the viewController to exit in Storyboard? If so, why?
Basically if you are just dimissing a presented UIViewController or popping a UIViewController from the navigation stack,you don't need to use unwind segues although it does the same for you.
But think of a case where there are UINavigationControllers A,B,C and then a RootViewController R
Then think of a condition
(Present) R -> A
(Push) AR -> XVController
(Push)XVController -> B
(Present)BR-> YVContoller
...and so on..
Now if you want to go back to YVController to your project RootViewController where you just started up.There is no way as popToRootViewController pops to the navigation stack of the B UINavigationController.Now what you do..Either use delegate or change window RootViewController which is not a good idea.
So you need to use unwind segue to overcome this.. A sample project to demonstrate the power of using it..

Pushing from ViewController to TabBarController takes delay

In my project, I have ViewController A for login, when I pressed the login button it show ViewController B where I have four buttons. When I click button1, I have showSegue direct to TabBarController and it has two tabs. Same as button 2,3,4 I have showSegue directs to NavigationController. Actually this is the hierarchy of my TabBarController and NavigationController:
Click Button 1 to:
TabBarController ->
Tab1 -> NavigationController -> ViewController1
Tab2 -> NavigationController -> ViewController2
Click Button 2,3,4 to:
NavigationController -> ViewController
I used storyboard in this project running Swift 2, Xcode 7. When I click each buttons, it takes almost 1-2 seconds delays especially on iPad real device. A bad user experience. It takes me a time to search some answers but sadly i didn't found a solution, that's why I asked it here..
Thanks in advance.
Maybe you should think about using an async method to load your controllers when you press the buttons.
Try to use
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), {
//Background Thread (Get your values - Run your requests)
dispatch_async(dispatch_get_main_queue(), {
//Update the UI (Give values to your outlets)
});
})
guys thanks for sharing your idea but i figured out the problems... Actually in my apps, I override one of navigation method which I changed the background of navigation bar with an image. The image is too large that's why it caused some delay before it present the next view. After changing the size of the image, it works properly now.

How to dismiss or unwind a view in Swift (Xcode 6)?

I have been scouring the web for the best and most proper way to dismiss/unwind a view using Swift and cannot find a definitive answer. For ease of concept, I have two views and have linked one to the other with a button and a segue using "show." How do I return to the original view (no data needs to be passed)?
you can try adding a button action to your ViewController2 and add in the code below. Your ViewController2 will dismiss when the button is being pressed.
dismissViewControllerAnimated(true, completion: nil)

Does anyone know what the new Exit icon is used for when editing storyboards using Xcode 4.5?

Right-clicking the Exit icon yields an empty window. Can't Ctrl-drag a connection to any IB elements or corresponding source files. Docs give no love. Doesn't appear in nib files, only storyboards. My assumption is that it's a corollary to segues, but I don't see any new methods to back it up. Anyone?
I had a hard time following the accepted answer so here is more detail.
Given the photo below on view controller C you can "exit" back to any view controller in the segue path.
ViewController A you can write:
- (IBAction)done:(UIStoryboardSegue *)segue {
// Optional place to read data from closing controller
}
ViewController B you can write:
- (IBAction)back:(UIStoryboardSegue *)segue {
// Optional place to read data from closing controller
}
ViewController C you control drag from "back" button to the green exit option and select back:
ViewController C you control drag from "done" button to the green exit option and select done:
Note: Even though the methods are on other view controllers they show up for the ViewController C's exit. Control dragging and selecting a method defines which ViewController to unwind to.
There's a lot of information in the WWDC video "Session 407 - Adopting Storyboards in your App."
Say you have two view controllers linked by a segue. Implement the following exit action on the first view controller:
- (IBAction)done:(UIStoryboardSegue *)segue {
NSLog(#"Popping back to this view controller!");
// reset UI elements etc here
}
Then, on Storyboard scene for the second view controller, Ctrl-drag from a UI element, such as a button, to the exit icon at the bottom of this view controller. The done: action you added to the code of the first controller will appear as an option. Now, activating the button you Ctrl-dragged to the exit icon will pop back to the first view controller and maintain its original state (ie UI elements such as text input supposedly still intact).
As addition to Eric answer here is how it works with swift:
The function you add to the destination controller looks like:
#IBAction func backFromOtherController(segue: UIStoryboardSegue) {
NSLog("I'm back from other controller!")
}

Resources