0

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.

TheCodeTalker
  • 685
  • 6
  • 14
Noorul
  • 3,386
  • 3
  • 32
  • 54
  • Can you clarify on what exactly you need help with? I'm not quite seeing which part you're stuck on. – clawesome Jan 06 '20 at 13:53
  • i am editing the some content on profile screen. when i unawarely click on message or any other tab, the edited data from profile screen all are lost. so, made some functionality, that describes how i am doing it. – Noorul Jan 06 '20 at 14:04
  • The tabBarController should persist your controller though, if you're losing data when selecting a different tab I would think that you're clearing the information in your viewDidDisappear or viewDidAppear in that specific controller. – clawesome Jan 06 '20 at 14:25
  • I want to show the alert if the user is editing on something on screen. How do I do that? is there any inbuilt function? – Noorul Jan 06 '20 at 14:31
  • I do not believe there is anything built in specifically for what it sounds like you're trying to do. In your `shouldSelect viewController:` function, you could store the selected index, then in the callback for your UIAlertController that you're displaying the dialog, you could programmatically set the selected tab for the tabBarController to be that selected index. – clawesome Jan 06 '20 at 14:43

0 Answers0