I am new to iOS Development.I have some requirement . I want to check the particular condition when another tab is selected.
Here is the part of UITabviewController delegate method code.
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if(Constants.isEditing!>0){
showAlert(tabBarController,viewController)
return false
}
return true
on the above code , show alert will shown Alert dialog with Yes
and No
Button.
when the user tap of yes
, user can able to switch tab.
example:
There are following tabs.
Search
Message
Profile
Settings
Now I am in the Profile section and editing my profile. when I click on message or any other tab, it's gone to another tab. even though, I am editing my profile.
so, all the data I entered has lost. so, I put one static variable on UITabViewController and increasing the count when the user type something on edit profile textfield. so, in above function you see, Constants.isEditing > 0
means, we should show alert dialog and if the user selected the yes
button means, I set the isEditing to 0 and allow the user to go message or any other tab.
if the user selected No
means, we let the user to be in same screen itself.
on this requirement Anyone please help me to solve this issue. ? Helps will be appreciated.
EDIT:
So, here tabBarController function is called when i click on settings
tab.
The actual functionality of this function is, ask the user to proceed with settings
click. Here i said false
to the system and showing the alert dialog.
So, it's showing the AlertDialog with Yes
No
button.that is OK. But when the user select Yes
, we cant move to Settings
tab. because, we don't have any references that the Settings
tab clicked. so, it's still on that screen.
Hope the description explains clearly. Update me if i missed anything.