1

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?

Hitesh
  • 896
  • 1
  • 9
  • 22
  • Look into these links https://stackoverflow.com/questions/19764282/how-to-inherit-parent-to-two-viewcontrollers-that-each-have-the-same-field https://stackoverflow.com/questions/30822817/connecting-objects-with-two-view-controllers-in-swift https://stackoverflow.com/questions/27449771/iboutlet-to-two-viewcontrollers-on-two-storyboards-is-that-possible – Gagan_iOS Sep 14 '17 at 16:56

1 Answers1

4

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141