SwiftUI tableview warning

I put a TableView inside a TabView, which is quite simple.


struct ContentView: View {

var body: some View {

TabView() {

FirstTab().tabItem { Text("Tab Label 1") }.tag(1)

Text("Tab Content 2").tabItem { Text("Tab Label 2") }.tag(2)

}

}

}


struct FirstTab: View {

var body: some View {

List {

ForEach (data) { point in

Text("No. \(point.id) point distance is \(point.r).")

}

}

}

}


But when FirstTab appears, Xcode gave me this warning:


2019-11-15 11:47:25.696111+0800 testTab[1775:51174] [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: 0x7f9ba1038000; baseClass = UITableView; frame = (0 0; 414 756); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x60000149c990>; layer = <CALayer: 0x600001abab40>; contentOffset: {0, 0}; contentSize: {414, 0}; adjustedContentInset: {0, 0, 83, 0}; dataSource: (null)>


What does this mean? Why table view "has not been added to a window"?

This is benign. It's appearing because SwiftUI is using a table view in the background to perform layout calculations without actually putting it on-screen. In the SwiftUI use case, this is to be expected, and doesn't seem to have any particular negative effects.

It may not have an impact on UX, but it's not good practice to leave warning messages. @andykuang, did you find a solution?

SwiftUI tableview warning
 
 
Q