I know this appears to be a duplicate of some other questions, but the answers are not working for me.

  1. I have created a single view app.
  2. In the storyboard I added a subview to my main view.
  3. I have a label on my main view and another label on my subview.
  4. I have created a class of type UIView and added it as the custom class for the subview.
  5. I can ctrl-drag my label on my main view to the main view controller class. But when I try to ctrl-drag my label on my subview to my custom class, I cannot get the connection to occur.
  6. I have even typed the property information and tried to make the connection manually to no avail.

Things have changed a bit in the latest version of Xcode's Interface Builder. Can somebody tell me what I am missing? There is literally no code here. I am just testing trying to connect outlets to a subview with a custom class.

The first image shows that I have set up the custom class and added a property but I cannot make the connection.

Main view and subview in Interface Builder - custom class is set

The second image shows the main view label is connected in the main view's controller.

Main view and subview in Interface Builder - main view's label is connected

The third image shows that there are no outlet connections for the subview's label.

Main view and subview in Interface Builder - cannot connect subview's label

推荐答案

You can manually write the IBOutlet property declaration in the @interface of the custom view subclass, and assuming you've defined the base class of your subview in IB, then you can drag from the outlet circle in the code back to the control in the scene.

enter image description here

Or, as you point out, Warren Burton suggested both this technique and another in his answer to this other question, Can't Wire to Subview in IB.

Objective-c相关问答推荐

如何使用 iOS 7 SpriteKit 粒子向非游戏的 iOS 应用程序添加粒子效果?

Objective-C,如何获取 UTC 时区的当前日期?

performSelector 的返回值:

'if not' 的 Objective-C 预处理器指令

iOS 应用程序下一个键不会转到下一个文本字段

dispatch_semaphore_dispose 上的 EXC_BAD_INSTRUCTION(代码=EXC_I386_INVOP,子代码=0x0)

在我的 iOS Mail 和 Safari 应用程序中支持 Open In... 菜单项

了解 performSegueWithIdentifier

iOS6:supportedInterfaceOrientations 不起作用(被调用但界面仍然旋转)

为什么 NSOrderedSet 不继承自 NSSet?

UIKeyboardBoundsUserInfoKey 已弃用,改用什么?

在字符串Objective-c中连接字符串

如何推送两个视图控制器但只为第二个设置动画过渡?

在 DEBUG 模式下启用和禁用 NSLog

cellForRowAtIndexPath 是如何工作的?

如何本地化 iOS 故事板

通过将另一个字符串重复给定次数来创建 NSString

在 UITableView 的 iOS 文档目录中列出保存的文件?

xcode 5.1 中的 Arm64 架构

围绕其中心旋转 UIView 保持其大小