Override IBOutlet properties from superclass?

I would like to create a superclass in an environment that modifies the properties of an IBOutlet. However, I would like the subclass to be connected to the storyboard, since I do not want to connect the controls to the class within the framework.

For example, a superclass in my structure looks like this:

public class MySuperDetailViewController: UIViewController { @IBOutlet public weak var titleLabel: UILabel? @IBOutlet public weak var dateLabel: UILabel? @IBOutlet public weak var contentWebView: UIWebView? ... } 

Then in the subclass, I would like to control the drag and drop controls in the subclass. Therefore, I must disclose these properties by overriding them. I am trying to do this, but this will not allow me:

 class MyDetailViewController: MySuperDetailViewController { @IBOutlet weak var titleLabel: UILabel? @IBOutlet weak var dateLabel: UILabel? @IBOutlet weak var contentWebView: UIWebView? } 

The error I get is: Cannot override with a stored property 'titleLabel', 'dateLabel', and 'contentWebView' .

How can I do this or better approach this?

+5
source share
1 answer

Do not try to recreate variables in a subclass; IBOutlet variables still exist. You can still connect them inside Interface Builder in several ways.

  • Utilities (right panel) → Connection Inspector - drag and drop IBOutlets from the list.
  • Document structure (left pane) - drag from MyDetailViewController
  • Drag from the yellow circle when you have the UIViewController selected in Interface Builder

Note. All subclasses of the UIViewController inherit an IBOutlet named view ; this property already exists in Interface Builder, even if you cannot click + drag to connect it.

+9
source

Source: https://habr.com/ru/post/1246365/


All Articles