NickCoder
NickCoder

Reputation: 1530

Multiple Inheritance Issue while using baseViewController and ButtonBarPagerTabStripViewController

I am using the XLPagerTabStrip library for the tab bar in my app and also I have created a base view controller for some unique views to be used on multiple screens So as swift doesn't allow multiple inheritances I cannot inherit baseviewcontroller in the view controller where ButtonBarPagerTabStripViewController is used because both controllers inherited UIViewController

What I want is want view added to the base view to be displayed on the main tab bar screen. baseviewcontroller has multiple views imported in it and I am managing these views on each view separately, the button is just for example.

This is main tab bar view controller:

class mainSearchViewController: ButtonBarPagerTabStripViewController { }

And this is my base view controller :

class baseTalentViewController: UIViewController { 
    var testButton = UIButton()

    override func viewDidLoad() {
        super.viewDidLoad()
        setupUIForButton()
    }

    func setupUIForButton() {
        self.view.addSubview(self.testButton)
        testButton.translatesAutoresizingMaskIntoConstraints = false
        testButton.trailingAnchor.constraint(equalTo: self.view!.safeAreaLayoutGuide.trailingAnchor, constant: -5).isActive = true
        testButton.centerYAnchor.constraint(equalTo: self.view!.safeAreaLayoutGuide.centerYAnchor).isActive = true
        self.view.bringSubviewToFront(self.testButton)
    }

}

I want this test button to appear on mainSearchViewController

I tried using protocol but I am not able to achieve what I want, so help me resolve this.

Upvotes: 1

Views: 158

Answers (1)

uvios
uvios

Reputation: 41

I good solution will be to develop independent views sepratly intead of creating them in one "BaseViewController" add import these views in your controller where required. this will decouple your code.

in perticluraly your solution although its not the best way Can create baseTalentViewController a child of ButtonBarPagerTabStripViewController or use two base controllers one with ButtonBarPagerTabStripViewController as parent other with UIViewController as parent (very stupid solution but if you want to keep it this way its the only way out)

Upvotes: 0

Related Questions