我的导航控制器数量不断增加 [英] My Navigation Controller Count Keeps Growing

查看:17
本文介绍了我的导航控制器数量不断增加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 iOS 开发的新手,对 Storyboards/Segues/Pushing 和 Popping 不太确定.

I'm new to iOS dev and am not entirely sure on Storyboards/Segues/Pushing and Popping.

所以在我的应用中,我有一个导航控制器,其中有 5 个视图控制器,从一个到另一个.

So in my app I have a navigation controller with 5 view controllers leading from one to another.

当它到达最后一个视图控制器时,我有一个转场到第一个,并且我在 prepareForSegue 方法中列出了一些任务.

When it reaches the last view controller i have a segue to the first and I have a few tasks listed in the prepareForSegue method.

出于好奇,我决定检查 [self.navigationController.viewControllers count] 会发生什么.我发现它一直在增长和增长,这感觉"不正确.

Out of curiosity I decided to check what happens to the [self.navigationController.viewControllers count]. I found that it keeps growing and growing which doesn't 'feel' correct.

我是否正确处理返回第一个屏幕?prepareForSegue 方法很有用,因为它允许我将一些数据发送回第一个 segue.是否可以说当您返回时清除该导航控制器上的所有视图?

Am i handling going back to the first screen correctly? The prepareForSegue method is useful as it allows me to send some data back to the first segue. Is it possible to maybe say when you go back clear all views on that navigation controller?

谢谢

推荐答案

您可以使用 unwind segue.这是一个很好的教程:

You can use an unwind segue. Here's a good tutorial:

pragmaticstudio.com/blog/2013/2/5/unwind-segues

确保在将它连接到故事板之前创建展开动作方法,否则当您拖动到退出"时它不会显示.这是我第一次设置时最困惑的部分.本教程以正确的顺序进行,因此如果您按照它进行操作应该没问题.

Make sure to create the unwind action method before you wire it up in the storyboard otherwise it won't show up when you drag to 'Exit'. That was the most confusing part for me when I first set one up. The tutorial does it in the correct order so if you follow it you should be fine.

此外,这里有一个我放在一起的示例,展示了如何在 unwind segue 中将数据传回.它使用模态呈现的视图控制器,但技术是相同的:

Also, here's a sample I put together showing how to transfer data back in an unwind segue. It uses a modally presented view controller but the technique is the same:

github.com/soleares/AddToTableView

这篇关于我的导航控制器数量不断增加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆