Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between Modal and Push segue in Storyboards?

Can someone explain to me what is the exact difference between modal and push segue?

I know that when we use push the segue gets added to a stack, so when we keep using push it keeps occupying memory?

Can someone please show me how these two are implemented?

Modal segues can be created by simply ctrl-click and dragging to destination but when I do that with the push my app crashes.

I am pushing from a button to a UINavigationController that has a UIViewController.

like image 594
Gaurav_soni Avatar asked Feb 22 '12 10:02

Gaurav_soni


People also ask

What is use of Segue in Swift?

Swift version: 5.6. Segues are visual connectors between view controllers in your storyboards, shown as lines between the two controllers. They allow you to present one view controller from another, optionally using adaptive presentation so iPads behave one way while iPhones behave another.

What is modal in Swift?

Developed originally for the iPad, Popovers are similar to modals. They are a type of view controller that requires user attention. Modals take over the window, which on the bigger real estate of the iPad, is often a waste of space.

What is a segue Xcode?

A segue defines a transition between two view controllers in your app's storyboard file. The starting point of a segue is the button, table row, or gesture recognizer that initiates the segue. The end point of a segue is the view controller you want to display.


1 Answers

A push Segue is adding another VC to the navigation stack. This assumes that VC that originates the push is part of the same navigation controller that the VC that is being added to the stack belongs to. Memory management is not an issue with navigation controllers and a deep stack. As long as you are taking care of objects you might be passing from one VC to another, the runtime will take care of the navigation stack. See the image for a visual indication: NavStack

A modal Segue is just one VC presenting another VC modally. The VCs don't have to be part of a navigation controller and the VC being presented modally is generally considered to be a "child" of the presenting (parent) VC. The modally presented VC is usually sans any navigation bars or tab bars. The presenting VC is also responsible for dismissing the modal VC it created and presented.

Hope this helps.

like image 103
LJ Wilson Avatar answered Nov 16 '22 01:11

LJ Wilson