Обзор:
У меня есть проект SwiftUI, который показывает ContentView
ContentView показывает представление вкладок с 2 вкладками:
- Текст
- OrderListView (использует список)
Шаги для воспроизведения:
Когда сделано следующее, в консоль выдается предупреждение:
- Нажмите на 2-й Вкладка
- Нажмите на 1-ю вкладку
- Обратите внимание на предупреждение в консоли:
Предупреждение:
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:
0x7fddc985ae00; baseClass = UITableView; frame = (0 0; 414 852); clipsToBounds = YES;
autoresize = W+H; gestureRecognizers = <NSArray: 0x600003053120>; layer = <CALayer:
0x600003e784c0>; contentOffset: {0, 0}; contentSize: {414, 0}; adjustedContentInset: {0,
0, 83, 0}; dataSource: (null)>
Код:
ContentView.swift
import SwiftUI
struct ContentView: View {
var body: some View {
TabView {
Text("aaa")
.tabItem {
Image(systemName: "1.square.fill")
Text("1st tab")
}
OrderListView()
.tabItem {
Image(systemName: "2.square.fill")
Text("2nd tab")
}
}
.font(.headline) }
}
OrderListView.swift:
import SwiftUI
struct OrderListView : View {
var orders = [Order]()
var body: some View {
List(orders) { order in
Text("bbb")
.font(.body)
}
}
}
Order.swift
import Foundation
class Order : Identifiable {
let id : Int
init(id: Int) {
self.id = id
}
}