1

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.

NickCoder
  • 1,504
  • 2
  • 23
  • 35
  • 1
    Faced the exact same issue, for now I am creating another ViewController, which inherits from the baseviewcontroller, and has a single view, which will contain the viewcontroller that inherits from ButtonBarPagerTabStripViewController. – ParasGarg Sep 24 '22 at 08:26

1 Answers1

0

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)

uvios
  • 41
  • 5
  • 1
    I have created separate views and all are imported into the base view because these views will be added on multiple controllers so it would be easier to handle. Also I have multiple views imported in base view I cannot manually add on multiple view controllers. button is just for understanding – NickCoder Aug 01 '22 at 16:31