Xlpagertabstrip: I created a custom cell with a badge. How to access the badge to update the number programatically?

Created on 26 Dec 2017  路  3Comments  路  Source: xmartlabs/XLPagerTabStrip

I have my xib set up and the screen now looks like this :

image

I have my cell.swift like this :

    @IBOutlet weak var ivTabIcon: UIImageView!
    @IBOutlet weak var lblTitle: UILabel!
    @IBOutlet weak var viewBadge: UIView!
    @IBOutlet weak var lblBadge: UILabel!

And I configure the title and icon like this in my parent view controller :

    override func configure(cell: TabImageCellCollectionViewCell, for indicatorInfo: IndicatorInfo) {
        cell.ivTabIcon.image = indicatorInfo.image
        cell.lblTitle.text = indicatorInfo.title
    }

But however this is useless because this is a one time configure, I would like to change the badge number after pulling some info from api. Which must happen outside of this configure function.

How do I access the badge property?

Thanks

Most helpful comment

Hi, @junweimah , i have did the same thing to access and update the badge,Its works, i have made the following function to do that.

func updateBadge(){
   if let cell = buttonBarView.cellForItem(at: IndexPath(item: 1, section: 0)) as? FriendCollectionViewCell{
        cell.badge.isHidden = self.totalFriendRequest == 0 ? true : false
        cell.badgeCounter.text =  self.totalFriendRequest.description
      }
}
  1. cell.badge = is UIview with red Background.
  2. cell.badgeCounter = is number of request counter label.

    1. if let cell = buttonBarView.cellForItem(at: IndexPath(item: 1, section: 0)) as? FriendCollectionViewCell = Here FriendCollectionViewCell is your custom cell which you have made.

      Note: In my case i need to update only second cell of Bar, that is why i have tried to get the IndexPath(item: 1, section: 0)

Please let me know if you are not clear yet.

All 3 comments

Hi, @junweimah , i have did the same thing to access and update the badge,Its works, i have made the following function to do that.

func updateBadge(){
   if let cell = buttonBarView.cellForItem(at: IndexPath(item: 1, section: 0)) as? FriendCollectionViewCell{
        cell.badge.isHidden = self.totalFriendRequest == 0 ? true : false
        cell.badgeCounter.text =  self.totalFriendRequest.description
      }
}
  1. cell.badge = is UIview with red Background.
  2. cell.badgeCounter = is number of request counter label.

    1. if let cell = buttonBarView.cellForItem(at: IndexPath(item: 1, section: 0)) as? FriendCollectionViewCell = Here FriendCollectionViewCell is your custom cell which you have made.

      Note: In my case i need to update only second cell of Bar, that is why i have tried to get the IndexPath(item: 1, section: 0)

Please let me know if you are not clear yet.

Hi @kevadiyaVishal , It's working.

This post was very helpful for me.
Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Mohammed-Eliass picture Mohammed-Eliass  路  4Comments

Ariavm95 picture Ariavm95  路  4Comments

rkittinger picture rkittinger  路  3Comments

unittesting0 picture unittesting0  路  3Comments

dowhilenet picture dowhilenet  路  4Comments