Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh Tab Bar Items in swift ios

I do app like Instagram with tab bar items. In app I have simple user and company user.

I have main ViewController:

MainTabBarController: UITabBarController

with 5 tab bar items. And each item has own ViewController

I need refresh MainTabBarController when user is Simple user it is 5 items and when user is Company user it is 4 items. How to refresh or reload without close app?

One solution I already do with UserDefaults, but need close app.

Platform iOS > 9.0, Swift 3.0

like image 228
Zhanserik Avatar asked May 30 '17 12:05

Zhanserik


People also ask

How do I add items to the tab bar in Swift?

Press Cmd+N to create a new SwiftUI View, calling it “MainView”. Creating tabs is as easy as putting different views inside an instance of TabView , but in order to add an image and text to the tab bar item of each view we need to use the tabItem() modifier.

How do you refresh a view controller?

In the ViewDidLoad include a loadData() function to prepare the data. This is executed in the initial run. When you want to reload, call loadData() again to get the data from model. In a tableView call reloadData() or in a regular view setNeedsDisplay().


1 Answers

Use setViewControllers(_:animated:)

myTabBarController.setViewControllers(myViewControllers, animated: true)
like image 84
Jože Ws Avatar answered Oct 10 '22 12:10

Jože Ws