Xcode - 一个笔尖,两个类 - 第二类中的插座未连接?
我有一个 nib 文件,想要将一些元素连接到一个类(即 AppDelegate)中的方法,并将一些元素连接到另一个类(这只是一个 NSObject)。所以架构看起来像这样:
buttonOne -> 【主类设置】 按钮二 -> [auxCals套装] 文本字段一-> mainClass.field 文本字段二 -> auxClass.field
两个 [set] 操作连接到两个类并且工作正常,但只有 textField 一个连接到主类,也就是 AppDelegate。
TextFieldTwo 不起作用(来自 auxClass 中的 [field setStringValue:] 调用。在 mainClass applicationDidFinishLaunching 方法中分配了 auxClass 的一个实例。
我认为这就是问题所在 - 运行时无法将某些元素连接到 auxClass,因为它没有但当我在 [auxClass set:] 中的一个方法上添加一个中断时,它表明 auxClass.field 连接到了 NULL 之外的其他东西
。最简单的例子 - 除了像选项卡视图这样的东西,其中两个选项卡功能位于两个不同的类中,
是否有一些“笔尖加载魔法”在实例化 auxClass 时需要在 AppDelegate 的幕后执行?
I've got a single nib file and want to connect some elements to methods in one class (which is the AppDelegate) and some to another class (which is just an NSObject). So the schema looks like this
buttonOne -> [mainClass set]
buttonTwo -> [auxCalss set]
textFieldOne -> mainClass.field
textFieldTwo -> auxClass.field
The two [set] actions are connected to the two classes and work fine, but only textField one is connected to mainclass, which is also the AppDelegate.
TextFieldTwo doesn't work (from a [field setStringValue:] call in auxClass. An instance of auxClass is allocated in the mainClass applicationDidFinishLaunching method.
I thought this was the problem - that the runtime cannot connect some of the elements to auxClass because it didn't exist yet. But when I put a break on a method in [auxClass set:], it showed that auxClass.field was connected to something other than NULL.
Generally I'd see this as a bad design pattern in anything more than the simplest example - except for something like a tab view where two tabs functionality is in two different classes.
Is there some "nib loading magic" that goes on behind the scenes of the AppDelegate that I need to perform when I instantiate the auxClass?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不应该在代码中分配/初始化 auxClass 的新副本;它已经在笔尖中为您完成了。只需在 mainClass 中创建一个 IBOutlet 并在 Interface Builder 中将其连接到 nib 中的 auxClass 对象即可。请参阅此最近的问题。
You shouldn't alloc/init a new copy of auxClass in code; it's already done for you in the nib. Just make an IBOutlet in mainClass and hook it up in Interface Builder to the auxClass object in the nib. See this recent SO question.