我在使用可可项目时遇到问题。我显示一个键盘组成的NSButtons,我想,当我点击其中一个键,标签添加到NSTextField。我有一个控制器,我用作单例,所以每个键知道如何访问控制器。在控制器,我有一个出口链接到NSTextField。当我点击一个键,没有任何反应。所以我在mouseDown事件上使用了 NSLog(@%@,[[[OakController] sharedInstance] textarea]),在控制台输出, code>(null)。
I'm having trouble with a cocoa project. I'm displaying a keyboard composed of NSButtons, and I'd like that when I click on one of the keys, the label is added to a NSTextField. I have a controller that I use as a singleton, so each key "knows" how to access the controller. In the controller, I have an outlet linked to the NSTextField. When I click on a key, nothing happens. So I used something like NSLog(@"%@", [[[OakController] sharedInstance] textarea]) on a mouseDown event, and in the console output, I get (null).
很长的故事,我的插座设置为nil,我不知道为什么
Long story short, my outlet is set to nil, and I don't know why it is that way, or how to solve that...
以下是控制器的代码: gist.github/1090564 。
Here's the code of the controller : gist.github/1090564. Sorry for the lack of syntax coloring.
推荐答案非常感谢您阅读。
我的猜测是,你实际上有多个实例的OakController,而不是一个像你所期望的。你把一个蓝色的多维数据集拖到你的IB文档,并将其自定义类更改为OakController?这将每次分配和初始化一个新的对象。我想你的sharedInstance方法也分配和初始化一个实例。
My guess is that you actually have multiple instances of OakController instead of one like you expect. Did you drag a blue cube into your IB document and change its custom class to OakController? That will allocate and initialize a new object each time. I'd guess that your sharedInstance method also allocates and initializes an instance.
尝试添加一个awakeFromNib方法到OakController,并添加一个断点。记录自我的指针值。在第二种情况下,插座意外地为nil,也记录自己的指针地址。
Try adding an awakeFromNib method to OakController, and add a break point. Log self's pointer value. In your second case were the outlet is unexpectedly nil, also log self's pointer address.
更多推荐
为什么我的插座没有?
发布评论