本文介绍了如何使用 IBOutlet 子类化变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的特定类的所有后代都有一个 UILabel 实例变量.所以在我的父类中,我有 var label: UILabel.我也想在 sublclass 中使用它,但作为 IBOutlet.我该怎么做?

All descendants of my specific class are to have a UILabel instance variable. So in my parent class I have var label: UILabel. I want to have it in the sublclass as well, but as an IBOutlet. How do I do this?

我添加了同名的IBOutlet,并在两个变量声明中添加了weak.但我收到关于无法覆盖存储的属性"的错误消息.

I added the IBOutlet of the same name, and added weak to both variable declarations. But I get an error about "Cannot override with a stored property".

我该怎么做?是否可以不必实例化超类的版本,因为我只想要它用于子类化?

How should I be doing this? And is it possible to not have to instantiate the superclass' version as I just want it for subclassing?

推荐答案

只需在超类中添加 IBOutlet 修饰符即可.

Just add the IBOutlet modifier in the superclass.

这篇关于如何使用 IBOutlet 子类化变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 15:45