XCode 6:无法将任何IBOutlet连接到ViewController

时间:2023-01-17 17:00:35

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没有链接到相关的Objects工作。

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:

更清楚:

XCode 6:无法将任何IBOutlet连接到ViewController

The class is defined in the Custom Class section, so I can't find the problem

该类在Custom Class部分中定义,因此我找不到问题

XCode 6:无法将任何IBOutlet连接到ViewController

What should I do? Btw I'm using obj-c not swift, I found some related answer but all about swift.

我该怎么办?顺便说一下,我使用obj-c并不是很快,我发现了一些相关的答案,但都是关于swift的。

Thanks

谢谢

16 个解决方案

#1


49  

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

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

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

#2


23  

In your storyboard hierarchy select the View Controller,

在故事板层次结构中,选择View Controller,

XCode 6:无法将任何IBOutlet连接到ViewController

In the right pane Custom Class section Class, select the drop down and your desired view controller.

在右窗格“自定义类”部分“类”中,选择下拉列表和所需的视图控制器。

XCode 6:无法将任何IBOutlet连接到ViewController

#3


5  

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.

希望这可以帮助。

#4


4  

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

#5


4  

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个图标(View Controller,First Responder和Exit)...现在查看Utility区域选择Identity Inspector,并在“Custom Class”中选择定制视图控制器。

Hope this helps. Xcode is hard!!

希望这可以帮助。 Xcode很难!!

#6


2  

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:

我在界面构建器中找不到一种方法,所以这样做:

  1. Open the .xib file with a text editor: right click the file > open as > source code

    使用文本编辑器打开.xib文件:右键单击文件>打开>源代码

  2. In the <objects> node find the <placeholder> node with the property placeholderIdentifier="IBFilesOwner" and replace the value in customClass="MyOldControllerName" with your new controller name: customClass="MyNewControllerName"

    节点中找到带有placeholderIdentifier =“IBFilesOwner”属性的 节点,并将customClass =“MyOldControllerName”中的值替换为新的控制器名称:customClass =“MyNewControllerName”

And all your IBOutlets will work as normal again.

并且您的所有IBOutlets将再次正常工作。

#7


1  

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版本,问题就消失了。

#8


0  

Maybe try to delete the outlet from the menu in the storyboard (in your screenshot) and drag it again of the element.

也许尝试从故事板中的菜单中删除插座(在屏幕截图中)并再次拖动元素。

#9


0  

Okay, let's check iff it is the lack of a module name.

好的,让我们检查是否缺少模块名称。

  1. In your storyboard ViewController, type in the name of module. (the project name)
  2. 在Storyboard 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.Clcick在另一个领域外面。当你回到模块字段时它可能没有,但现在会有一个项目名称的下拉菜单项。

  1. Select your project name and see if everything is good.
  2. 选择您的项目名称,看看是否一切都很好。

If there are still issues I will post photos.

如果仍有问题,我会发布照片。

#10


0  

Seems to be a workspace issue. Try to remove project form a workspace and add it again. It helped in my case.

似乎是一个工作空间问题。尝试从工作区中删除项目并再次添加。它对我的情况有帮助。

#11


0  

I had this, affected all projects on my machine, swift and objective c and drove me mad for ages. Finally also noticed that I could not use the refractor to rename classes either.

我有这个,影响了我机器上的所有项目,迅速和客观的c,并让我疯了很多年。最后还注意到我无法使用折射器重命名类。

The fix for me was:

我的修复是:

  1. Close xcode
  2. 关闭xcode
  3. Delete ~/Library/Developer/Xcode/DerivedData (just doing this on its own did not work!!)
  4. 删除〜/ Library / Developer / Xcode / DerivedData(只是单独执行此操作不起作用!!)
  5. Delete all user data for all my projects using the following from the directory that contains all my projects e.g. /src (be careful with this command!):
  6. 使用包含我所有项目的目录中的以下内容删除所有项目的所有用户数据,例如/ src(小心这个命令!):

find . -name 'xcuserdata' -exec rm -rf {} \;

找 。 -name'xcuserdata'-exec rm -rf {} \;

If you want to do it by hand just do the following for all your projects Delete .xcodeproj/project.xcworkspace/xcuserdata Delete .xcodeproj/xcuserdata/.xcuserdatad

如果你想手动完成,只需对你的所有项目执行以下操作删除.xcodeproj / project.xcworkspace / xcuserdata删除.xcodeproj / xcuserdata / .xcuserdatad

  1. Get Spotlight to re-index the drive all my projects were on (not sure if this was required
  2. 获取Spotlight以重新索引我的所有项目所在的驱动器(不确定是否需要这样做
  3. Re-boot machine
  4. 重启机器

Everything sprang back into life !

一切都回归生活!

#12


0  

I was having this same issue.

我遇到了同样的问题。

It turns out I renamed my view controller class and file name. In storyboard, I had the stale value in the right pane, Custom Class -> Class. So the IBOutlets were not aligning because there were none in the missing class, which is where it was expecting to find the defined outlets.

事实证明我重命名了我的视图控制器类和文件名。在storyboard中,我在右侧窗格中有过时值,Custom Class - > Class。所以IBOutlets没有对齐,因为缺少的类中没有,这是它期望找到定义的出口的地方。

Filling in the correct class name of the View Controller in the Custom Class field in the right pane fixed my issue.

在右侧窗格的“自定义类”字段中填写View Controller的正确类名,修复了我的问题。

XCode needs to be more verbose if you have a bad class name in the Custom Class fields.

如果您在自定义类字段中有一个错误的类名,则XCode需要更详细。

#13


0  

no one solution fixed my same problem... But i have solved by:

没有一个解决方案解决了我同样的问题...但我已经解决了:

  • close xcode
  • 关闭xcode
  • renaming the folder of the project
  • 重命名项目的文件夹
  • open xcode
  • 打开xcode

and then the outlets will be back again

然后出口将再次回来

I hope that this solution is the right one for the people who have the same problem

我希望这个解决方案对于遇到同样问题的人来说是正确的

#14


0  

In Xcode 6.3 I needed to close Xcode and restart the Mac. Restarting Xcode alone didn't do it for me.

在Xcode 6.3中,我需要关闭Xcode并重启Mac。单独重新启动Xcode并不适合我。

I've had 6.3 for a long time and my problem was with new projects I was creating to test some things. Definitely not an upgrade issue this time.

我已经有6.3很长一段时间了,我的问题是我正在创建的新项目来测试一些东西。这次绝对不是升级问题。

#15


0  

I have Xcode 6.3 and saw similar issue. Finally few edits in .h file resolved my issue. If your interface has IBOutlet defined as

我有Xcode 6.3并且看到了类似的问题。最后,.h文件中的少量编辑解决了我的问题。如果您的接口已将IBOutlet定义为

@interface NavigationViewController :UIViewController
{
  IBOutlet UILabel *lblName;
}

change this to and in .m file add @synthesize lblName;

将此更改为.m文件并添加@synthesize lblName;

@interface NavigationViewController :UIViewController
{
   __weak  UILabel *lblName;
}

@property (nonatomic, weak) IBOutlet UILabel *lblName;

#16


0  

I was having this same problem, with no view outlet available to link to. The only way I was able to fix it was to change the owner class of the XIB file to "UIViewController," make the link, and then change it back to my intended custom view controller class. The link stayed and all was well.

我遇到了同样的问题,没有可用于链接的视图插座。我能够修复它的唯一方法是将XIB文件的所有者类更改为“UIViewController”,生成链接,然后将其更改回我想要的自定义视图控制器类。链接停留,一切都很顺利。

#1


49  

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

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

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

#2


23  

In your storyboard hierarchy select the View Controller,

在故事板层次结构中,选择View Controller,

XCode 6:无法将任何IBOutlet连接到ViewController

In the right pane Custom Class section Class, select the drop down and your desired view controller.

在右窗格“自定义类”部分“类”中,选择下拉列表和所需的视图控制器。

XCode 6:无法将任何IBOutlet连接到ViewController

#3


5  

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.

希望这可以帮助。

#4


4  

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

#5


4  

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个图标(View Controller,First Responder和Exit)...现在查看Utility区域选择Identity Inspector,并在“Custom Class”中选择定制视图控制器。

Hope this helps. Xcode is hard!!

希望这可以帮助。 Xcode很难!!

#6


2  

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:

我在界面构建器中找不到一种方法,所以这样做:

  1. Open the .xib file with a text editor: right click the file > open as > source code

    使用文本编辑器打开.xib文件:右键单击文件>打开>源代码

  2. In the <objects> node find the <placeholder> node with the property placeholderIdentifier="IBFilesOwner" and replace the value in customClass="MyOldControllerName" with your new controller name: customClass="MyNewControllerName"

    节点中找到带有placeholderIdentifier =“IBFilesOwner”属性的 节点,并将customClass =“MyOldControllerName”中的值替换为新的控制器名称:customClass =“MyNewControllerName”

And all your IBOutlets will work as normal again.

并且您的所有IBOutlets将再次正常工作。

#7


1  

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版本,问题就消失了。

#8


0  

Maybe try to delete the outlet from the menu in the storyboard (in your screenshot) and drag it again of the element.

也许尝试从故事板中的菜单中删除插座(在屏幕截图中)并再次拖动元素。

#9


0  

Okay, let's check iff it is the lack of a module name.

好的,让我们检查是否缺少模块名称。

  1. In your storyboard ViewController, type in the name of module. (the project name)
  2. 在Storyboard 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.Clcick在另一个领域外面。当你回到模块字段时它可能没有,但现在会有一个项目名称的下拉菜单项。

  1. Select your project name and see if everything is good.
  2. 选择您的项目名称,看看是否一切都很好。

If there are still issues I will post photos.

如果仍有问题,我会发布照片。

#10


0  

Seems to be a workspace issue. Try to remove project form a workspace and add it again. It helped in my case.

似乎是一个工作空间问题。尝试从工作区中删除项目并再次添加。它对我的情况有帮助。

#11


0  

I had this, affected all projects on my machine, swift and objective c and drove me mad for ages. Finally also noticed that I could not use the refractor to rename classes either.

我有这个,影响了我机器上的所有项目,迅速和客观的c,并让我疯了很多年。最后还注意到我无法使用折射器重命名类。

The fix for me was:

我的修复是:

  1. Close xcode
  2. 关闭xcode
  3. Delete ~/Library/Developer/Xcode/DerivedData (just doing this on its own did not work!!)
  4. 删除〜/ Library / Developer / Xcode / DerivedData(只是单独执行此操作不起作用!!)
  5. Delete all user data for all my projects using the following from the directory that contains all my projects e.g. /src (be careful with this command!):
  6. 使用包含我所有项目的目录中的以下内容删除所有项目的所有用户数据,例如/ src(小心这个命令!):

find . -name 'xcuserdata' -exec rm -rf {} \;

找 。 -name'xcuserdata'-exec rm -rf {} \;

If you want to do it by hand just do the following for all your projects Delete .xcodeproj/project.xcworkspace/xcuserdata Delete .xcodeproj/xcuserdata/.xcuserdatad

如果你想手动完成,只需对你的所有项目执行以下操作删除.xcodeproj / project.xcworkspace / xcuserdata删除.xcodeproj / xcuserdata / .xcuserdatad

  1. Get Spotlight to re-index the drive all my projects were on (not sure if this was required
  2. 获取Spotlight以重新索引我的所有项目所在的驱动器(不确定是否需要这样做
  3. Re-boot machine
  4. 重启机器

Everything sprang back into life !

一切都回归生活!

#12


0  

I was having this same issue.

我遇到了同样的问题。

It turns out I renamed my view controller class and file name. In storyboard, I had the stale value in the right pane, Custom Class -> Class. So the IBOutlets were not aligning because there were none in the missing class, which is where it was expecting to find the defined outlets.

事实证明我重命名了我的视图控制器类和文件名。在storyboard中,我在右侧窗格中有过时值,Custom Class - > Class。所以IBOutlets没有对齐,因为缺少的类中没有,这是它期望找到定义的出口的地方。

Filling in the correct class name of the View Controller in the Custom Class field in the right pane fixed my issue.

在右侧窗格的“自定义类”字段中填写View Controller的正确类名,修复了我的问题。

XCode needs to be more verbose if you have a bad class name in the Custom Class fields.

如果您在自定义类字段中有一个错误的类名,则XCode需要更详细。

#13


0  

no one solution fixed my same problem... But i have solved by:

没有一个解决方案解决了我同样的问题...但我已经解决了:

  • close xcode
  • 关闭xcode
  • renaming the folder of the project
  • 重命名项目的文件夹
  • open xcode
  • 打开xcode

and then the outlets will be back again

然后出口将再次回来

I hope that this solution is the right one for the people who have the same problem

我希望这个解决方案对于遇到同样问题的人来说是正确的

#14


0  

In Xcode 6.3 I needed to close Xcode and restart the Mac. Restarting Xcode alone didn't do it for me.

在Xcode 6.3中,我需要关闭Xcode并重启Mac。单独重新启动Xcode并不适合我。

I've had 6.3 for a long time and my problem was with new projects I was creating to test some things. Definitely not an upgrade issue this time.

我已经有6.3很长一段时间了,我的问题是我正在创建的新项目来测试一些东西。这次绝对不是升级问题。

#15


0  

I have Xcode 6.3 and saw similar issue. Finally few edits in .h file resolved my issue. If your interface has IBOutlet defined as

我有Xcode 6.3并且看到了类似的问题。最后,.h文件中的少量编辑解决了我的问题。如果您的接口已将IBOutlet定义为

@interface NavigationViewController :UIViewController
{
  IBOutlet UILabel *lblName;
}

change this to and in .m file add @synthesize lblName;

将此更改为.m文件并添加@synthesize lblName;

@interface NavigationViewController :UIViewController
{
   __weak  UILabel *lblName;
}

@property (nonatomic, weak) IBOutlet UILabel *lblName;

#16


0  

I was having this same problem, with no view outlet available to link to. The only way I was able to fix it was to change the owner class of the XIB file to "UIViewController," make the link, and then change it back to my intended custom view controller class. The link stayed and all was well.

我遇到了同样的问题,没有可用于链接的视图插座。我能够修复它的唯一方法是将XIB文件的所有者类更改为“UIViewController”,生成链接,然后将其更改回我想要的自定义视图控制器类。链接停留,一切都很顺利。