Android teem
Android teem

Reputation: 830

Updating UITabBarController items title at runtime

I have a UITabBarController implemented in my project. I am working on it and it was working as expected. Now before asking my question let me tell you how many tab bar items I have. The following are the tab bar items I have in my app:

  1. Main List
  2. Cart List
  3. Favorites
  4. Contact List

Now when I click on Main List it opens respective ViewController. And it happens for all other tabs as well.

But now in first tab (View controller) I have to perform some operations which needs to update the text or title of tab bar 2, tab bar 3, and tab bar 4.

For example, after performing some operations I want my tab bar title in following manner

  1. Main List(12)
  2. Car List(05)
  3. Favorites(00)
  4. Contacts List(100)

I hope you got my point. I have seen badges in some apps, but I really do not want that. If there is any idea or link. I am using Swift 4.

Upvotes: 1

Views: 428

Answers (1)

Pravin
Pravin

Reputation: 51

I hope this will work for you.

You can fetch TabBarController from your viewController which is located in any tab.

you need to paste this code in any of your viewController and you can find all tabBar items. Now you need to identify tabBar item and update accordingly.

    let tabVC = self.tabBarController
    if let items = tabVC?.tabBar.items {
        for item in items {
            item.title = "Your Title"
        }
    }

Upvotes: 1

Related Questions