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

SOLVED: Problems with TabView

Forums > SwiftUI

Dear all,

I am pretty new to the swift community so please apologize if this is a low-brainer.

I have the following problem: I have an app that is throwing the following warning since I changed to a TabView Layout:

"[TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView: 0x7fcc03055600; baseClass = UITableView; frame = (0 0; 414 852); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x600002e25500>; layer = <CALayer: 0x60000200bf20>; contentOffset: {0, 0}; contentSize: {414, 0}; adjustedContentInset: {0, 0, 83, 0}; dataSource: (null)>"

I successfully re-created the problem with a straight-forward structure (see below). I would be very happy for any suggestions what's going on here:

1) Model

class PersonList {

    var personList: [Person]

    init() {
        personList = [Person]()
        personList.append(Person(surName: "Jane", name: "Smith"))
        personList.append(Person(surName: "John", name: "Smith"))
    }
}

class Person: Identifiable {

    let id = UUID()
    var surName: String
    var name: String

    init(surName: String, name: String) {
        self.surName = surName
        self.name = name
    }
}

2) Single Tab View

struct TestView: View {

    let personList: [Person]

    var body: some View {
        List (personList) { person in
            Text("Hallo \(person.name)")
        }
    }
}

3) Content View that includes two Tabs

struct ContentView: View {
    var personList = PersonList()

    var body: some View {
        TabView {
            Text("Test")
                .tabItem {
                    Text("Tab 1")
            }
            TestView(personList: personList.personList)
                .tabItem {
                    Text("Tab 2")
            }
        }
    }
}

The problem arises as soon as you click on tab 2 and then go back to tab 1.

Many thanks in advance and best regards,

Julian

4      

@twostraws  Site AdminHWS+

This is an internal Apple message, and not for us to worry about. We're all seeing the same message no matter what, so it's definitely for Apple to fix!

11      

Thank you so much for taking your time to reply!

3      

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!

Thanks Paul, I noticed the same thing today!

3      

I encountered this today. I found that it occurs when going from a tab with a non-list view to a tab with a list view. If both tabs have list views the error is not reported.

I would like to find a work around, because while I am learning it is very distacting to have the console filled with noise - hiding any important messages that might be scrolled away.

I tend to be a bit obsessive about keeping my console empty of warnings, errors, and extraneous messages.

Any help appreciated.

3      

@emin  

Found this as well when i was trying out diffable data source. So happy its not just me :)

3      

I also noticed this same issue. I even took out the TabView and am controlling how the navigation works withint he app from an injected EnvironmentObject that I'm essentially just checking to see which view should be loaded from within the ContentView(). I actually have a question regarding this also, for some reason my List views when I click on them it will take me to the details page like it's supposed to, but then almost immediately takes me back to the list view. Sometimes it will remain on the details view, but others it takes you right back and is really frustrating.

This is my LessonsView():

struct LessonsView: View {
@EnvironmentObject var appData: AppData

private var lessons = [LessonModel](arrayLiteral: LessonModel(id: UUID.init(), title: "title", subtitle: "subtitle"))

var body: some View {
    NavigationView {
        List(lessons, id: \.id) { lesson in
            LessonRowView(lesson: lesson)
        }
        .navigationBarItems(leading:
            Button("Go Back") {
                // todo
                self.appData.updateActiveView(.map)
            })
        .navigationBarTitle(Text("The Farm"))
    }
}
}

and this is the LessonRowView():

struct LessonRowView: View {
var lesson: LessonModel

var body: some View {
    NavigationLink(destination: LessonDetailView(lesson: lesson)) {
        VStack(alignment: .leading) {
            Text("\(lesson.title)")
                .font(.headline)
            Text("\(lesson.subtitle)")
            .font(.subheadline)
                .foregroundColor(Color.gray)
        }
    }
}
}

and lastly, my LessonDetailView():

struct LessonDetailView: View {
@State var lesson: LessonModel!

var body: some View {
    ScrollView {
        VStack(alignment: .leading) {
            ZStack{
                Rectangle()
                    .foregroundColor(Color.gray)
                    .frame(maxWidth: .infinity, maxHeight: 200)
                VStack(alignment: .leading) {
                    Text("\(lesson.title)")
                        .font(.headline)
                        .foregroundColor(Color.white)
                        .bold()
                    Text("\(lesson.subtitle)")
                        .font(.subheadline)
                        .foregroundColor(Color.white)
                        .italic()
                        .foregroundColor(Color.gray)
                    Spacer()
                }
                .padding()
                .frame(maxWidth: .infinity, maxHeight: 200)
            }

            Text("Full Description goes here")
                .font(.subheadline)
            .padding()
            Spacer()
        }
    }
}
}

Is anyone else experiencing this behavior? It doesn't seem to matter how I construct the list. At first I was getting the collection of Lesson's using an ObservableObject and thought maybe that's what the issue was, so I replaced it with essentially a hard-coded single item (shown above) and it STILL does the same thing. Any help would be greatly appreciated!

4      

Nice not only me

3      

I get the ''This is an internal Apple message, and not for us to worry about. We're all seeing the same message no matter what, so it's definitely for Apple to fix!'

Then I have a TextField and when I make the first character change to it I immediately get '[general] Connection to daemon was invalidated'. Google search for this gives no useful information.

Then if I do one or more things the app dies with Thread 1: signal SIGABRT and no other output.

So Is there at least a way to avoid hitting the 'internal Apple message' even its for Apple to fix? I'm guessing it causing the app in my case to crash soon after.

3      

@roblack,

I dealt with the same issue when using diffable data source. I realized I wasn't setting tableView.dataSource = myDiffableDataSource. After I did that, the error went away!

3      

@fkuhl  

I encountered this error. It disappeared after I tracked down and eliminated a nested NavigationView.

3      

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.