View Controller加载两次-如何修复它? [英] View Controller Loads Twice - How Do I Fix It?

查看:40
本文介绍了View Controller加载两次-如何修复它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题原因

当我将新的Swift类文件添加到我的iOS项目中时,我觉得我犹豫不决,将其重命名,删除并创建了一个新文件.我认为我实际上是举棋不定,所以我将其重命名了几次.

When I added a new Swift class file to my iOS project, I decided I was indecisive and renamed it, deleted it, and created a new file. I think that I was actually so indecisive that I renamed it a few times.

问题

现在,viewController加载两次.我实际上可以看到过渡发生了两次,并且在测试过程中,我可以看到viewDidLoad在控制台中运行了两次.

Now that viewController loads twice. I can literally see the transition happen twice and, during testing, I can see my viewDidLoad run twice in my console.

常用修补程序

我知道要检查的第一个解决方案是重复的segues/segue调用.检查您的文档大纲,以查看是否有一个以上的序列.就我而言,这绝对不是情节提要或viewController中的segue问题.

I know the first solution to check for is duplicate segues / segue calls. Check your document outline to see if there's more than one segue. In my case, it is definitely not a segue problem in the storyboard or the viewController.

我的罕见情况

我发现有人遇到两次相同的负载问题,这是由于重命名造成的:

I found someone who had the same load-twice problem and it was because of the rename:

他们说,这是我做的重命名,这是问题的根源,而且不容易解决,因为重复项现在位于我的XML文件中.但是,此XML文件在哪里,以及如何编辑它以删除该类的原始实例?我不知道.

They said it was the renaming I did that is at the root of my problem and it is not easy to fix because the duplication is now in my XML file. But where is this XML file and how do I edit it to erase the original instance of the class? I have no idea.

那么我该如何解决两次加载问题?我只希望ViewController具有正常的顺序!

So how do I solve this loads-twice issue? I just want my viewController to have a normal segue!

推荐答案

解决了我的问题!

如果您弄乱了一个类的名称(或它的文件名),并且遇到了我遇到的相同的两次加载"问题,那么您可能很难解决它.我发现的唯一建议的解决方案是说从头开始创建新项目并复制内容.但是,相反...

If you messed around with a class's name (or it's file name) and have the same "loads twice" issue that I was having, you might be having a hard time solving it. The only suggested solutions I found said to create a new project from scratch and copy stuff over. BUT, instead...

这是有史以来最简单的解决方案:

重命名两次加载的viewController的类!不必担心文件,但可以担心其中的视图控制器类.您的XML文件可能与原始类名重复,但是将您的类重命名为全新的类,就可以了.

Rename the class of the viewController that's loading twice! Don't worry about the file, but the view controller class within it. Your XML file probably has duplicates of the original class name, but rename your class to something entirely new and you should be okay.

这篇关于View Controller加载两次-如何修复它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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