swiftrightbarbuttonitemxlpagertabstrip

XLPagerTabStrip: How to add different bar buttons for different tabs using ButtonBarPagerTabStripViewController


I have three tabs, each tab is having different number of rightBarButtonItem and have different actions.

for eg. 1st tab has two right bar buttons Phone and Search, 2nd tab has three right bar buttons Add, Delete and edit, and 3rd tab has two right bar buttons Done and More. I don't have any idea how to add this.

Please suggest some idea. Thanks in advance.


Solution

  • You can add below function in our ViewController which is inherited ButtonBarPagerTabStripViewControllerand check toIndex is 0 or 1 or 2 and then customise your rightBarButtonItems

    override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
    
    if toIndex == 0 {
    
        self.navigationItem.rightBarButtonItems = nil
    
        // add new barButtons
    
    }
    else if toIndex == 1 {
    
        self.navigationItem.rightBarButtonItems = nil
    
        // add new barButtons
    
    
    }
    else {
    
        self.navigationItem.rightBarButtonItems = nil
    
        // add new barButtons
    }}