ios Xcode 6:无法将任何 IBOutlet 连接到 ViewController
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26203970/
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
Xcode 6: can't connect any IBOutlet to ViewController
提问by lorenzop
After upgrading to Xcode 6, I opened an old project (that contains a subproject, so it has many targets) and I noticed that no link from my Storyboard ViewContoller to the relative Objects works.
升级到 Xcode 6 后,我打开了一个旧项目(其中包含一个子项目,因此它有很多目标),我注意到从 Storyboard ViewContoller 到相关对象的链接没有工作。
For example I have a ViewController with a TableView inside and now I cant do can't do anyhing with it because the connection is missing, I can't even redefine a new IBOutlet in the VC because the arrow in the storyboard from the VC won't connect to anything.
例如,我有一个带有 TableView 的 ViewController,现在我不能做任何事情,因为缺少连接,我什至无法在 VC 中重新定义新的 IBOutlet,因为 VC 的故事板中的箭头赢了不连接任何东西。
To be more clear:
更清楚一点:
The class is defined in the Custom Class section, so I can't find the problem
类是在自定义类部分定义的,所以我找不到问题
What should I do? Btw I'm using obj-c not swift, I found some related answer but all about swift.
我该怎么办?顺便说一句,我使用的是 obj-c 而不是 swift,我找到了一些相关的答案,但都是关于 swift 的。
回答by JJBoursier
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...
我在实际使用的应用程序中遇到了完全相同的问题,将 XCode 从 5.xxx 更新到 6.1。对我有用的解决方法是删除每个视图控制器的引用并将它们重新添加到项目中......
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 Tom Howard
In your storyboard hierarchy select the View Controller,
在故事板层次结构中选择视图控制器,
In the right pane Custom Class section Class
, select the drop down and your desired view controller.
在右窗格自定义类部分中Class
,选择下拉列表和所需的视图控制器。
回答by Adam Nierzad
I've experienced similar behaviour in Xcode 6.1.1 when trying to add the first outlet to a new view.
尝试将第一个插座添加到新视图时,我在 Xcode 6.1.1 中遇到了类似的行为。
Tried removing the references and adding the files again as suggested above with no success.
尝试按照上面的建议删除引用并再次添加文件,但没有成功。
What I did find worked was writing the first property on the new view by hand. I just popped in:
我确实发现有效的是手动在新视图上编写第一个属性。我刚刚弹出:
@property NSString *temp;
I could then attach my outlets in the normal way. Just delete the temporary property once you've added your first outlet.
然后我可以以正常方式连接我的插座。添加第一个出口后,只需删除临时属性。
Hope this helps.
希望这可以帮助。
回答by user462990
Maybe I can help In my case the problem was that the viewController.swift file was not connected to the StoryBoard. The solution is to click in the Upper border of the view on the storyboard beside the 3 icons (View Controller, First Responder and Exit)...now look over in the Utility Area choose Identity Inspector, and in "Custom Class" choose the custom view controller.
也许我可以提供帮助 在我的情况下,问题是 viewController.swift 文件没有连接到 StoryBoard。解决方案是单击故事板上视图的上边框,旁边有 3 个图标(视图控制器、第一响应者和退出)...现在在实用程序区域中查看选择身份检查器,然后在“自定义类”中选择自定义视图控制器。
Hope this helps. Xcode is hard!!
希望这可以帮助。Xcode 太难了!!
回答by hugey
It seems typing the outlet first (swift):
似乎首先输入插座(快速):
@IBOutlet weak var someViewOutlet: UIView!
and then dragging from IB the outlet to the far right type in the above code works.
然后从 IB 将插座拖到上面代码中最右边的类型。
Restarting Xcode resolves the issue (sometimes). Using Xcode 6.1
重新启动 Xcode 可以解决问题(有时)。使用 Xcode 6.1
回答by Daniel Moreira
Here's the proper solution i believe.
这是我相信的正确解决方案。
If you renamed the controller in code, you need to update the .xib file.
如果在代码中重命名了控制器,则需要更新 .xib 文件。
I could not find a way to do it in the interface builder, so do this:
我在界面构建器中找不到这样做的方法,所以这样做:
Open the .xib file with a text editor: right click the file > open as > source code
In the
<objects>
node find the<placeholder>
node with the propertyplaceholderIdentifier="IBFilesOwner"
and replace the value incustomClass="MyOldControllerName"
with your new controller name:customClass="MyNewControllerName"
使用文本编辑器打开 .xib 文件:右键单击文件 > 打开为 > 源代码
在
<objects>
节点中找到<placeholder>
具有该属性的节点placeholderIdentifier="IBFilesOwner"
并将值替换为customClass="MyOldControllerName"
您的新控制器名称:customClass="MyNewControllerName"
And all your IBOutlets will work as normal again.
您所有的 IBOutlets 将再次正常工作。
回答by lorenzop
Thanks to everyone who commented.
感谢所有评论的人。
It is a bug of Xcode 6 / 6.0.1. Downloaded and installed the 6.1 version and the problem disappeared.
这是 Xcode 6 / 6.0.1 的一个错误。下载并安装了6.1版本,问题消失。
回答by Antoine
Maybe try to delete the outlet from the menu in the storyboard (in your screenshot) and drag it again of the element.
也许尝试从故事板(在您的屏幕截图中)的菜单中删除插座,然后再次将其拖到元素中。
回答by Steve Rosenberg
Okay, let's check iff it is the lack of a module name.
好的,让我们检查一下是否缺少模块名称。
- In your storyboard ViewController, type in the name of module. (the project name)
- 在您的故事板 ViewController 中,输入模块的名称。(项目名称)
2.Clcick outside in another field. When you go back to the module field it may say none, but now there will be a dropdown menu entry for your project name.
2.在另一个字段中单击外部。当您返回模块字段时,它可能会说无,但现在您的项目名称将出现一个下拉菜单条目。
- Select your project name and see if everything is good.
- 选择您的项目名称,看看是否一切正常。
If there are still issues I will post photos.
如果还有问题我会发照片。
回答by P_O
Seems to be a workspace issue. Try to remove project form a workspace and add it again. It helped in my case.
似乎是工作区问题。尝试从工作区中删除项目并重新添加。它对我有帮助。