How to update title of the child dynamically
Before submitting issues ...
- Make sure you are using XLPagerTabStrip latest release or master branch version.
- Make sure your Xcode version is the latest stable one.
- Check if the issue was already reported or fixed. We add labels to each issue in order to easily find related issues. If you found a match add a brief comment "I have the same problem" or "+1".
- Please do not use the issue tracker for personal support requests. Stack Overflow is a better place for that where a wider community can help you!
When submitting issues, please provide the following information to help maintainers to fix the problem faster:
- Environment: XLPagerTabStrip, Xcode and iOS version you are using.
- In case of reporting errors, provide Xcode console output of stack trace or code compilation error.
- Any other additional detail such as example code that you think it would be useful to understand, reproduce and solve the problem.
any updates guys? need this urgently
I want to implement the same thing. @shadowTech827 any solution?
Hey @vaibhav-varshaaweblabs ,
For the above : I'am saving a track of the new cell and old cell and wrote a little complex logic to support my use case.
When setting up the Tabs:
changeCurrentIndexProgressive = {
[weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage:
CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
guard changeCurrentIndex == true else { return }
oldCell?.label.textColor = .black
newCell?.label.textColor = UIColor.themeRed()
print("oldCell: \(String(describing: oldCell?.label?.text)) newCell: \(String(describing:
newCell?.label?.text))")
if oldCell == nil {
if (condition1){
self?.currentCell = newCell
}
}else if newCell == nil{
if (condition 2){
self?.completedCell = oldCell
}else{
if self?.currentCell == nil {
self?.currentCell = oldCell
}else{
self?.completedCell = oldCell
}
}
}
Then updating the headers whenever needed
func updatetabHeaders() {
var current : IndicatorInfoProvider!
var completed : IndicatorInfoProvider!
if (condition1){
current = viewControllers[0] as! IndicatorInfoProvider
completed = viewControllers[1] as! IndicatorInfoProvider
}else{
current = viewControllers[1] as! IndicatorInfoProvider
completed = viewControllers[2] as! IndicatorInfoProvider
}
UIView.performWithoutAnimation({ [weak self] () -> Void in
guard let me = self else { return }
if self?.currentCell != nil {
self?.configureCell((self?.currentCell)!, indicatorInfo: current.indicatorInfo(for: me))
}
if self?.completedCell != nil {
self?.configureCell((self?.completedCell)!, indicatorInfo: completed.indicatorInfo(for: me))
}
})
}
In your Controller's IndicatorInfo function Change the title as per your need: Like in my case: func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
if (tabTitle == nil){
if condition 1{
tabTitle = "Title1"
}else{
tabTitle = "Title 2"
}
}
return IndicatorInfo(title : tabTitle!)
}
This solution may not be very good as it's a work around for my use case. When come to more tabs it will become complex as tracking the tabs will be too complex (i.e new cell and old cell)
P.S if any other solution do let me know. Thanks in advance
@shadowTech827 do you know how to do it when I have 3 tabs? since I don't know how to update the other cell (not old cell or new cell ) in changeCurrentIndexProgressive
if let pagerTabStrip = self?.parent as? ButtonBarPagerTabStripViewController {
pagerTabStrip.buttonBarView.reloadData()
}
I'm looking for this solution too. I need to update the label on tab when a key on firebase is updated. Anybody can help me?
Hi! I just find the solution. I used the @Bo-Bogdan answer in event of firebase. In childViewController that I wanted to update the tab label, I created a property 'tabBarTitle' that was used in indicatorInfo() to instantiate the IndicatorInfo. So, on update in Firebase I change the tabBarTitle's value and execute the reloadData:
class childViewController: UIViewController, IndicatorInfoProvider {
var tabBarTitle: String = "Initial value"
func indicatorInfo(for pagerTabStripController: PagerTabStripViewController) -> IndicatorInfo {
return IndicatorInfo(title: tabBarTitle)
}
override func viewDidLoad() {
super.viewDidLoad()
Database.database().reference()
.child(YOUR_PATH)
.observe(DataEventType.value, with: { (snapshot) -> Void in
let value = snapshot.value as? [String : AnyObject] ?? [:]
self.tabBarTitle = value[KEY_OF_VALUE] as? String ?? ""
if let pagerTabStrip = self.parent as? ButtonBarPagerTabStripViewController {
pagerTabStrip.buttonBarView.reloadData()
}
})
}
}
@Bo-Bogdan thank you, this worked!
This answer did not work for me as the ViewControllers are not initialized yet until the users advances to the page. It works for updates to the first tab, but any subsequent tabs do not have values.
So, the first tab has the title var set, but the others just have the initial value.
Maybe I am doing something wrong, but I have tried several approaches and all of them seem to have invalid values until the tab is selected.
Any help would be appreciated!!
Thank you @Bo-Bogdan for the answer! Awesome!
@Bo-Bogdan Thanks for the awesome answer, but the tab width doesn't fit update based on new text, any idea?
@Bo-Bogdan Thanks for the awesome answer, but the tab width doesn't fit update based on new text, any idea?
Hi jackylcs86 You found the solution??
My solution inspired by @Bo-Bogdan `func notifyParent(){ if let parentVC = self.parentVC {
if let selectedTabVC = parentVC.viewControllers.first(where: {$0 is SelectedTabViewController}) as? SelectedTabViewController {
let selected = viewModel.selectedStudents.count
if selected > 0 {
selectedTabVC.itemInfo = IndicatorInfo(title: "Selected Students(\(selected))")
} else {
selectedTabVC.itemInfo = IndicatorInfo(title: "Selected Students")
}
parentVC.buttonBarView.reloadData()
}
}
}`