为什么我的插座没有? [英] Why is my outlet nil?

查看:115
本文介绍了为什么我的插座没有?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用可可项目时遇到问题。我显示一个键盘组成的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...

以下是控制器的代码: https://gist.github.com/1090564

Here's the code of the controller : https://gist.github.com/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.

这篇关于为什么我的插座没有?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆