UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

TabView with TextField issues iOS 14.4

Forums > SwiftUI

Hi all,

I'm having an issue with iOS 14.4 in my app.

I have a TabView. On the third tab there is a TextField. Below the TextField, there is a button. The button is designed to submit the entry of the TextField, and move the user onto the next tab. So I have something like:

Button(action: {
                            hideKeyboard()

                            userDefaults.set(fbName, forKey: "fbName")         // set  UserDefault from the TextField

                            withAnimation {
                                currentTab = 3        // an @State that defines which tab the TabView is currently showing
                            }

                            })

This works perfectly on iOS 14.5 & 14.6.

However on iOS 14.4, the switch of tab in TabView doesn't happen unless the user manually hides the keyboard by tapping return, and then presses this button above.

i.e. The issue is when the TabView tries to switch tabs, but the user is still 'editing' in the TextField.

Because the TextField is still being edited it snags the change in view and keeps it on the tab with the TextField. This happens even though I call a hideKeyboard() function because while the keyboard is closing, the tab switch gets called... so it clashes. It needs to complete the closing of the keyboard before the tab is switched?

Can anyone help me with this? Would be very grateful! Thanks

2      

Hacking with Swift is sponsored by RevenueCat.

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.