简体   繁体   中英

Inherit outlets and actions in view controller

i've create TabBar App with 5 tabs, all 5 views are the same and each view include buttons to control one set of equipment, switch input to output on receiver and control volume, so 5 views correspond to 5 rooms. Now i have 5 different UIViewCOntrollers with nerly the same code, inherited from UIViewController .

But i think it should be one RoomViewController, inhereted from UIViewController , and RoomViewCOntroller shold be used for each room, something like this

class RoomViewController: UIViewController {

    @IBOutlet weak var videoSat: UIButton!

   func lockAudioLabel(sender: UIButton) {
      if sender.isSelected {
         return
      } 
      videoSat.isSelected = false
   }

  @IBAction func videoSatSelect(_ sender: UIButton) {

    //send command to equipment
    //make some actions
    lockVideoLabel(sender: sender)
  }
}

And Room1ViewController is

class Room1ViewController: RoomViewController {
}

All rooms have scene in storyboard

So the question is there any way to use one set of iboulets and ibactions in RoomViewController class and inherit them for example in Room1ViewContoller? And how to access them?

So the question is there any way to use one set of iboulets and ibactions in RoomViewController class and inherit them for example in Room1ViewContoller?

The @IBOutlet properties and @IBAction methods you declare in RoomViewController are inherited by subclasses such as Room1ViewController.

But what is not inherited is the design in the nib. When you instantiate a subclass like Room1ViewController, it loads its own view, not some other view controller's view. This loading takes place on a per-instance basis. Therefore, you still need to hook up the interface objects in the nib to the properties and methods in the class declaration. In other words, you still need to make outlets and actions in the nib, because this is a different view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM