Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override IBOutlet properties from super class?

I would like to create a super class in a framework that modifies IBOutlet properties. However, I would like a subclass to be connected to the storyboard, since I don't want to connect the controls to the class in the framework.

For example, the super class in my framework 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-drag controls onto the subclass. So I have to expose those properties by overriding. I'm trying to do this but it won't 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 to this?

like image 316
TruMan1 Avatar asked Apr 03 '16 22:04

TruMan1


1 Answers

Don't try to recreate the variables in the subclass; the IBOutlet variables still exist. You can still connect them inside of Interface Builder in a number of ways.

  1. Utilites (right panel) -> Connection Inspector - drag from the list of IBOutlets.
  2. Document Outline (left panel) - drag from MyDetailViewController
  3. Drag from the yellow circle when you have the UIViewController selected in Interface Builder

Note: All UIViewController subclasses inherit an IBOutlet named view; this property already exists in Interface Builder even though you can't click + drag to connect it.

like image 122
Kevin Avatar answered Sep 20 '22 02:09

Kevin