Iboutlet已连接但仍显示为空
我是 iPhone 开发新手,正在练习一些。正如许多教程所述,我将通过 IB 制作的 uilabel 连接到代码中的 IBOutlet,但在尝试设置它的文本时,它仍然说它为空?我在 .h 类上定义了 IBOutlet 对象,并通过 IB 很好地连接了它,没有出现问题,但不知道为什么它仍然为空。任何帮助将不胜感激。
I'm new at iPhone development and was practicing a bit. I connected a uilabel I made through IB to an IBOutlet in my code as many tutorials said but upon trying to set text of it it's still saying it's null? I defined the IBOutlet object on my .h class and connected it fine through IB without a problem but idk why it's still null. Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,首先,让我们删除一些无关的内容,专注于您需要的核心内容。
让我们知道当您在 InterfaceBuilder 中设置标签(显示)和操作(digitPressed:) 时会发生什么。
Okay, first things first, let's remove some of the extraneous stuff and focus on the core of what you need.
Let us know what happens when you've set the label (display) and the action (digitPressed:) in InterfaceBuilder.
尝试将您的属性更改为复制(或保留,但复制对于这种情况更惯用):
@property (copy) IBOutlet UILabel *display;
您的
分配
属性没有递增字符串的引用计数,因此不能保证在您需要它时它仍然存在。Try changing your property to copy (or retain, but copy is more idiomatic for this situation):
@property (copy) IBOutlet UILabel *display;
Your
assign
property is not incrementing the reference count for the string, thus there is no guarantee that it will still exist by the time you need it.