Xcode 6 中的错误 - 视图控制器没有名为(子视图)的插座

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25931865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:37:09  来源:igfitidea点击:

Error in Xcode 6 - view controller does not have an outlet named (subview)

iosobjective-cxcode

提问by Dale Townsend

I just got this error in one of my apps, and after checking some other apps the same error is happening. None of my IBOutletsand IBActionsare connected anymore. When I recreate the outlet by control-dragging into the .hfile, the outlet still displays the error in Connections Inspector > Outlets, saying (view controller) does not have an outlet named (subview). Before today I didn't have this problem, so is to do with Xcode 6? The view controller is referencing the correct class under Identity Inspector > Custom Class. I have deleted the derived data folder, removed the reference to the .h file, cleaned the project, and cleaned the build folder. None of that has worked and I can't progress with development until this issue is fixed.

我刚刚在我的一个应用程序中遇到了这个错误,并且在检查了其他一些应用程序之后发生了同样的错误。我的IBOutletsIBActions都不再连接了。当我通过控制拖动到 .h文件中重新创建插座时,插座仍然在Connections Inspector > Outlets 中显示错误,说(视图控制器)没有名为(子视图)的插座。在今天之前我没有这个问题,所以是用 Xcode 6 做的吗?视图控制器在Identity Inspector > Custom Class下引用正确的类。我删除了派生数据文件夹,删除了对 .h 文件的引用,清理了项目,并清理了构建文件夹。这些都没有奏效,在解决此问题之前,我无法进行开发。

Outlets show exclamation mark. Note 'easyLabel'

插座显示感叹号。 注意'easyLabel'

I disconnect easyLabel, and the outlet disappears. I can't reconnect it with drag and drop.

我断开easyLabel,插座消失了。 我无法通过拖放重新连接它。

Update: I just reopened the project after a couple of days and my outlets no longer have the exclamation mark next to them, and the 'easyLabel' outlet that I disconnected has reappeared. I didn't change anything, so I guess it's a bug in Xcode 6-6.1.

更新:几天后我刚刚重新打开了该项目,我的插座旁边不再有感叹号,并且我断开连接的“easyLabel”插座重新出现。我没有改变任何东西,所以我猜这是 Xcode 6-6.1 中的一个错误。

Update 2: This error came back. Exclamation marks next to every outlet. If I delete them I can't re-add them. Can't create new outlets. Also can't give a view controller a custom class. I really just want to make some progress on an app, but this issue keeps recurring. Really just can't stand it anymore. Any help would be appreciated.

更新 2:这个错误又回来了。每个插座旁边都有感叹号。如果我删除它们,我将无法重新添加它们。不能创建新的网点。也不能给视图控制器一个自定义类。我真的只是想在应用程序上取得一些进展,但这个问题一直重复出现。实在是忍不住了。任何帮助,将不胜感激。

回答by JJBoursier

Duplicate of: Xcode 6: can't connect any IBOutlet to ViewControllerbut here's the trick:

重复:Xcode 6:无法将任何 IBOutlet 连接到 ViewController但这里有诀窍:

You can also see that the link between the parent view and the custom class is broken (not visible anymore) which is a huge problem.

您还可以看到父视图和自定义类之间的链接已断开(不再可见),这是一个大问题。

I had the exact same issue with the app i'm working on actually, updating Xcode from 5.xxx to 6.1. The workaround that worked for me was to remove the reference of every view controller and re-add them to the project... Unfortunately, in some cases, mine actually, all the connections get lost again when XCode is closed.

我在实际使用的应用程序中遇到了完全相同的问题,将 Xcode 从 5.xxx 更新到 6.1。对我有用的解决方法是删除每个视图控制器的引用并将它们重新添加到项目中......不幸的是,在某些情况下,我的实际上,当 XCode 关闭时,所有连接都会再次丢失。

To everyone facing that issue, here's the (annoying) trick :

对于面临这个问题的每个人,这是(烦人的)技巧:

  • Step 1 :select both .h and .m view controller files
  • Step 2 :remove the referenceof those files
  • Step 3 :re-add the files to your project tree
  • Step 4 :open the storyboard, eventually re-build the project and smile
  • 第 1 步:选择 .h 和 .m 视图控制器文件
  • 第 2 步:删除这些文件的引用
  • 第 3 步:将文件重新添加到项目树中
  • 第 4 步:打开故事板,最终重新构建项目并微笑

I can understand those things could be reaaally annoying, but it worked for me... Hope it will help someone else !

我可以理解这些事情可能真的很烦人,但它对我有用......希望它会帮助别人!

回答by Salvador Mosti

I had the exact same problem and what was breaking my storyboards was the fact that my project was inside the folder /Dropbox (MyName)/projects/

我遇到了完全相同的问题,破坏我的故事板的是我的项目位于文件夹 /Dropbox (MyName)/projects/ 中

Apparently something about the name of the dropbox folder with spaces and ( ) was BREAKING my storyboard completely, try what I did and move your project completely to another folder and see if that helps :)

显然,带有空格和 ( ) 的 dropbox 文件夹的名称完全破坏了我的故事板,尝试我所做的并将您的项目完全移动到另一个文件夹,看看是否有帮助:)

回答by fizampou

I had the same problem, changed the class under identity Inspector > Custom Class to something else, saved it and then set it again to the correct one, after doing that the connections appeared normally.

我遇到了同样的问题,将身份检查器>自定义类下的类更改为其他内容,保存并再次将其设置为正确的类,然后连接正常显示。

回答by Cora Middleton

I had this issue with a Swift UIViewController subclass. I had removed the original view that IB created for me, and added a new view—which I was unable to connect.

我在 Swift UIViewController 子类中遇到了这个问题。我删除了 IB 为我创建的原始视图,并添加了一个我无法连接的新视图。

I went to the Identity inspector for the File's owner, and tried to re-enter it, thinking that maybe it had been modified somehow. Oddly, the class name did not autocomplete. It seemed like XCode was unable to actually see my class.

我去了文件所有者的身份检查员,并尝试重新输入它,认为它可能以某种方式进行了修改。奇怪的是,类名没有自动完成。XCode 似乎无法真正看到我的课程。

I tried removing and re-adding both the .swiftand .xibfiles, to no avail. XCode would allow me to manually type in my owning class name, but it would not autocomplete. It seemed to think it didn't exist, or wasn't valid for this context.

我尝试删除并重新添加.swift.xib文件,但无济于事。XCode 允许我手动输入我拥有的类名,但它不会自动完成。它似乎认为它不存在,或者在此上下文中无效。

Looking back at my code, I had something like the following:

回顾我的代码,我有如下内容:

extension SomeViewController {
    func foo() -> Bool {
        return false
    }
}

class SomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

It compiles just fine, but on a hunch, I removed the extension. I saved the file, went back to the .xib, and was able to set the File's Owner identity with autocompletion again. I was also able to wire up the view.

它编译得很好,但凭直觉,我删除了扩展名。我保存了文件,返回到.xib,并且能够再次设置具有自动完成功能的文件所有者身份。我也能够连接视图。

It would suck if extensions always broke things of course, so I tried again, this time with the extension after the class:

当然,如果扩展总是破坏事情会很糟糕,所以我又试了一次,这次是在课后扩展:

class SomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
    }
}

extension SomeViewController {
    func foo() -> Bool {
        return false
    }
}

Everything still worked in IB. To sanity check, I moved the extension back ahead of the class definition, and things were again horked.

一切都在 IB 中工作。为了进行完整性检查,我将扩展名移回了类定义之前,然后事情又变得很糟糕。

I took a look a the *-Swift.h generated by XCode, and at least relative to the affected class, there seemed to be no differences—regardless of where I put the extensions in the Swift file, they were always declared after the @interfacedefinition for the actual class in the header.

我查看了 XCode 生成的 *-Swift.h,至少相对于受影响的类,似乎没有区别——无论我将扩展放在 Swift 文件的哪个位置,它们总是在@interface定义之后声明对于标题中的实际类。

So, long story short, in my case this was due to Swift extensions (I say extensions because my actual code has many) coming before the class definition. I moved them after the class definition, and the problem went away.

所以,长话短说,在我的情况下,这是由于 Swift 扩展(我说扩展是因为我的实际代码有很多)出现在类定义之前。我在类定义之后移动了它们,问题就消失了。

回答by Will

For me I had to remove the reference and add back to my project the -XIB- file for my view controller. Simply removing the view controller .h/.m did not reset the outlets, but removing the .xib and adding it back did!

对我来说,我必须删除引用并将视图控制器的 -XIB- 文件添加回我的项目。简单地删除视图控制器 .h/.m 并没有重置插座,但是删除 .xib 并将其添加回来!

回答by Yu.

I was having the same issue but it was because i changed the name of the view controller in the Project Navigatorto MapViewControllerbut its name stayed the same (ViewController) in the code. once i changed it, it worked

我遇到了同样的问题,但这是因为我将Project Navigator中的视图控制器的名称更改为MapViewController但它的名称在代码中保持不变(ViewController)。一旦我改变了它,它就起作用了

回答by Yu.

Do you get the same issue if you connect the actions/outlets in Interface Builder instead of the assistant editor? For actions try control dragging from your object in IB to your first responder object (or whatever you have your class set to).

如果您在 Interface Builder 而不是助手编辑器中连接操作/出口,是否会遇到同样的问题?对于操作,尝试控制从 IB 中的对象拖动到您的第一响应者对象(或您将类设置为的任何对象)。

回答by Steve Riggins

@robb actually discovered the fix for this, but the issue he found was that the group in the project that mirrored a folder on disk used a different case.

@robb 实际上发现了解决这个问题的方法,但他发现的问题是项目中镜像磁盘文件夹的组使用了不同的案例。

So if the project group was Broken/classone.m

所以如果项目组是 Broken/classone.m

and on disk it was broken/classone.m

在磁盘上它坏了/classone.m

Interface builder could not find the files. Renaming either the group or the folder to match case resolved the issue.

界面生成器找不到文件。重命名组或文件夹以匹配大小写解决了该问题。

回答by Rivera

I have this problem only with @protocoldefined IBOutletsif I don't redefine them in the implementing class.

如果我不在实现类中重新定义它们,我只会在@protocol定义IBOutlets时遇到这个问题。

Probably the only thing we can do is file a bug.

可能我们唯一能做的就是提交错误

回答by Waqas Haider Sheikh

Why dont you update your xcode 6.0.1 to xcode 6.1, Apple have fixed many bugs.

为什么不将 xcode 6.0.1 更新到 xcode 6.1,Apple 已经修复了许多错误。

Download Xcode 6

下载Xcode 6