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

SOLVED: TabView: freeze when switching (randomly, but often)

Forums > SwiftUI

Hi everyone, my best wishes for this year to the swiftUI community, One of my views inside the TabView randomly freeze sometimes when navigate in the app and when i switch from a tab to an other. It is random, but make the tabView unusable for me (every button on the view become like disabled and doesn't work anymore). I feel like as soon as the views start to get a bit too complex, the tabView doesn't follow behind ... Maybe that it is a bug in SwiftUI (someone seems to have the same problem in apple dev forum https://developer.apple.com/forums/thread/124475). Has anyone else seen this as well ? I'm thinking about making my own tabView...

3      

I have not had this problem with TabView

You could try putting the TabView in the ....App.swift eg (This is the way Apple seem to do it)

@main
struct TestApp: App {
    var body: some Scene {
        WindowGroup {
            TabView {
                ContentOneView()
                    .tabItem {
                        Image(systemName: "1.square")
                    }

                ContentTwoView()
                    .tabItem {
                        Image(systemName: "2.square")
                    }
            }
        }
    }
}

or if still get it can you refactor the screen that "freezes" which may help.

3      

Hi @NigelGee, thank you for your feedback. i will try to put all in the app.swift, (if i can do it neatly, because i have all the login/registration views to handle, but if it works...).

3      

Problem solved !

I started by putting everything in app.swift, but the problem persisted so I refactored the view and in fact the culprit seemed to be a computed property. Thanks for putting me on the right path 👍

4      

TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!

Find out more

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.