What's the difference between unwind segues an

2020-02-12 11:32发布

The app I'm working on will need to implement a workflow to allow users to enter information in a form. Instead of using a scroll view, I'm planning to break it up into a bunch of separate view controllers, which will be managed by a navigation controller. I started by laying out all the form fragments in a storyboard, and began connecting all the push and unwind segues for the different parts of the form.

My question is, how is using all these push and unwind segues any better than simply using the pushViewController and popToViewController methods of my navigation controller, and skipping the storyboard altogether? Is there any difference in terms of memory management or performance? Wouldn't simply using push and pop be better practice in terms of design and maintainability? I can't find anything in the docs that addresses this.

3条回答
贪生不怕死
2楼-- · 2020-02-12 12:15

This is a great question.

In my 1st iOS project I followed the tutorials online and used storyboard segues etc. In my 2nd iOS project, I scrapped that and just push and pop view controllers.

I actually find it cleaner because with the storyboard way, you have to call performSegueWithIdentifier, and then you can prep the receiving view controller by sync'ing up with prepareForSegue. Why do this when you can just prep a view controller and push it all in one place?

Additionally, it decouples view controllers with transitions. It opens everything up and allows for more versatility..and more rapid development.

So my take on the matter is to just push and pop view controllers. Maybe somebody will make me look dumb but I've had much success just using this method.

查看更多
家丑人穷心不美
3楼-- · 2020-02-12 12:16

There's basically no difference in terms of what they do. The one thing that's good about using unwinds, is that you can pass data back to the controller you're unwinding to. If you use the pop methods, then you have to create a delegate protocol to do this. But a lot of this is subjective. You can use which ever is more comfortable for you. I like using the storyboard because it makes it easy to see the relationships between the controllers. Using storyboards can be a problem (so I've heard anyway) when you are working in a large team, so that's another consideration.

查看更多
相关推荐>>
4楼-- · 2020-02-12 12:28

For this case

(NAV_A --root view controller -- VC1) -- modally presents -- (NAV_B -- root view controller -- VC2 -- push -- VC3)

If you do pop at VC3 you will always reach VC2, ie view controller just below it. With unwind you can do what you did above plus , jump back to VC1 in one go.

Unwind can take you back to any point in the view controller hierarchy that you want but not pop.

查看更多
登录 后发表回答