LoginSignup
6
2

More than 5 years have passed since last update.

IBOutletをスーパークラスに持たせる方法

Last updated at Posted at 2018-05-22

状況

ViewController_A.swiftViewController_B.swiftが、同じUIViewを異なるStoryboardから接続している
そこで、スーパークラスを作ってそれを継承させてスマートにしたい

こうする

普通に@IBOutletを書いてOKだった。

class BaseVC: UIViewController {
    @IBOutlet weak var boardView: UIView!
}

class ViewController_A: BaseVC {
    // boardViewを扱える
}

class ViewController_B: BaseVC{
    // boardViewを扱える
}

異なるStoryboardと繋いでるから、継承元で接続しようがないのでは...?と思っていたが違うようです。

どうなってるの?

左側の接続情報(○のとこ)をクリックすればわかる。
Xcodeが接続情報を自動で管理してくれる。

スクリーンショット 2018-05-22 22.54.43.png

こんな感じの表示が出るはず。

出てないときは、手動でStoryboardから複数個のUIを一つのプロパティやアクションに繋ぎましょう

6
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
2