I need to add or remove items from the navigation bar when the user changes screen so I have a code like:
override func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) {
super.updateIndicator(for: viewController, fromIndex: fromIndex, toIndex: toIndex, withProgressPercentage: progressPercentage, indexWasChanged: indexWasChanged)
if indexWasChanged {
if toIndex == 2 {
rightBtn.alpha = 1
} else {
rightBtn.alpha = 0
}
}
}
rightBtn is simply a button on the right end of my navigation bar.
However during my testing runs I noticed that if the user taps on the ButtonBar instead of swiping to change screen, the fromIndex and toIndex is wrong. It will still be the values of the last change. E.g. when the user swipes from the third screen to the second, the fromIndex will be 2 and toIndex 1 but if the user taps on the third button on the bar, the fromIndex will still be 2 even though it is expected to be at 1 the toIndex will also stay at 1 even though now it should be 2. This results in my rightBtn not showing if the user swipes from the third screen then taps the bar back to the third.
Is there a way to obtain the correct toIndex during such a scenario or can it be fixed?
The first part is the buggy part where I navigate by tapping directly on the barbutton, the second part without the pointer is navigation by swiping with works fine, the Icon is only suppose to appear on the Third Tab