I have a search bar and when search button is pressed the default 0 index does not reload to fetch data. How to forcefully reload the tabview on button press.
I'm attaching the code below:
Button(action: {
print("I'm in..!",self.currentTab)
self.currentTab = 0
print(self.currentTab)
},
label: {
Image(uiImage: UIImage(named: "search_icon")!)
.resizable()
.frame(width:24,height:24)
.padding(5)
})
My TabView:
ZStack(alignment: .top){
TabBarView(currentTab: self.$currentTab)
}
TabView(selection: self.$currentTab) {
View1().tag(0)
View2().tag(1)
View3().tag(2)
View4().tag(3)
}
.environmentObject(viewModel)
.tabViewStyle(.page(indexDisplayMode: .always))
.edgesIgnoringSafeArea(.all)
.onChange(of: self.currentTab, perform: { newValue in
print(newValue)
self.selectedTab = newValue
})