Thanks John! Now I just need something that also works with SwiftUI πsee https://forums.developer.apple.com/thread/129897
Post
Replies
Boosts
Views
Activity
Thanks! And how would I manage that in SwiftUI with a List element?
Odd, now its working fine here as well. Thanks for the help all!
But if I remove that, the NavigationLink no longer works.
Nobody an idea?
Hi Claude31Sorry for the late reply, please see the complete code example below://
// ContentView.swift
// Two Navbars
//
// Created by Max on 2020-02-05.
// Copyright Β© 2020 Max. All rights reserved.
//
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView{
ScrollView{
VStack{
NavigationLink(destination: ListView1()){
Text("Tap me")
}
Text("Nothing here")
}
}
}
}
}
struct ListView1: View {
var body: some View {
List{
NavigationLink(destination: DetailView1()){
Text("Tap me one more time")
}
Text("Item 2")
Text("Item 3")
}
}
}
struct DetailView1: View {
var body: some View {
NavigationView{
ScrollView() {
VStack{
NavigationLink(destination: DetailView2()){
Text("Drill down more")
}
Text("Nothing here")
}
}
}
}
}
struct DetailView2: View {
var body: some View {
List {
Text("That's it")
Text("Nothing here")
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
I come from Netbeans and Java development and don't get me wrong but at least there it was pin pointing to the error in the stack thread pretty well. I am still struggeling to figure out in Xcode what piece exactly caused an error when the app crashes during execution ...
Thanks! I have changed my picker toPicker("From status", selection: $fromStatus2) {
ForEach(Self.orderStatusFromArray, id: \.self) { status in
Text(status)
}
}with $statusFrom2 being@State private var fromStatus2 = UserDefaults.standard.string(forKey: "view.orderHeaderFilter.fromStatus")To check the value in view.orderHeaderFilter.fromStatus on runtime I have added.onAppear{
print("^^^^^^^^^^^^^^^^^^^^^^^")
print(UserDefaults.standard.string(forKey: "view.orderHeaderFilter.direction")!)
print(UserDefaults.standard.string(forKey: "view.orderHeaderFilter.fromStatus")!)
print(UserDefaults.standard.string(forKey: "view.orderHeaderFilter.toStatus")!)
print("^^^^^^^^^^^^^^^^^^^^^^^")
}and that produces^^^^^^^^^^^^^^^^^^^^^^^
025
040
^^^^^^^^^^^^^^^^^^^^^^^but the picker is still not set to a default value of 025. When I change it to@State private var fromStatus2 = "025"it works fine. What am I missing here now?And by the way, is there a way to see the value of $fromStatus2 when I set a breakpoint on the picker? I tried but it did not show anything when hovering with the cursor over it.Max
Excellent answer, thanks for providing both alternatives! πMax
Ok, so I might have fixed (or broken?) it by changing it toDispatchQueue.main.async {
self.warehouseOrders.append(warehouseOrder)
}And now the view load fine the 1st time. If I now go back to the main menu and tap the button again to go back to the view, I get this error[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: 0x106104400; baseClass = UITableView; frame = (0 0; 0 0); clipsToBounds = YES; gestureRecognizers = <NSArray: 0x2810383f0>; layer = <CALayer: 0x281ece380>; contentOffset: {0, 0}; contentSize: {0, 0}; adjustedContentInset: {0, 0, 0, 0}; dataSource: <_TtGC7SwiftUIP10$1f7ddd2b419ListCoreCoordinatorGVS_20SystemListDataSourceOs5Never_GOS_19SelectionManagerBoxS2___: 0x105d6c370>>2020-01-19 23:08:57.856014-0500 WMS Toolbox[1286:554768] *** Assertion failure in -[_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore/UIKit-3901.4.2/UITableView.m:20402020-01-19 23:08:57.857277-0500 WMS Toolbox[1286:554768] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete section 0, but there are only 0 sections before the update'My call in the ContentView() isNavigationLink(destination: WarehouseOrderOverview().navigationBarTitle("Orders")) {
MenuButtonNavigation(title: "Order overview", color: Color.gray, icon: "doc.text.magnifyingglass").padding(.top)
}My WarehouseOrderOverview looks likestruct WarehouseOrderOverview: View {
@EnvironmentObject var settingStore: SettingStore
@ObservedObject var warehouseOrderController = WarehouseOrderController()
var body: some View {
List(warehouseOrderController.warehouseOrders){ warehouseOrder in
VStack{
OrderTableRow(warehouseOrder: warehouseOrder)
}
}.onAppear{
self.warehouseOrderController.loadData()
}
}
}Any ideas?
Hi Jim,Thanks for the advise, that seems to work now BUT when running it the console logs this message over and over again2020-01-19 21:01:50.535221-0500 WMS Toolbox[15833:27982195] [SwiftUI] Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.and Xcode highllights the code segment where I add entries to the array withself.warehouseOrders.append(warehouseOrder)Publishing changes from background threads is not allowed; make sure to publish values from the main thread (via operators like receive(on:)) on model updates.I guess I get that because I am fetching the data via an URLsession and that is managed in a different thread? So where exactly would I put the ".receive(on: RunLoop.main)" piece now? π