How do I subclass a variable with an IBOutlet?

前端 未结 4 1129
陌清茗
陌清茗 2020-12-16 13:57

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

4条回答
  •  盖世英雄少女心
    2020-12-16 14:10

    I realize that this question was posted a while ago, but since I just struggled with the same issue and finally came up with a solution, I figured I would still post my findings...

    I understand the problem to be as follows (at least that's the one I solved):

    How to have class A inherit from class B, with each class having its own XIB file with the some common IBOutlet properties? The goal being to be able to have the super class handle the actions related to the IBOutlets that are common to its subclass(es), while still being able to use Interface Builder to design the interface for the subclass(es).*

    In order to do so:

    • Make the IBOutlet connections in the superclass from the superclass' XIB files
    • Make the IBOutlet connections in the subclass from the subclass' XIB files, with the same IBOutlet property names as in the superclass for the ones you need to inherit.
    • Delete the declaration of the IBOutlet variables in the subclass

提交回复
热议问题