Hi,I am fetching data for my table view via a web service. Based on the request the result set can vary between 1 row and 20,000 rows. I know that usually my users are just interested in the first 1,000 rows of the data so I am wondering to have an approach where the initial web service call just loads the top 1,000 rows and when the user scrollls down the list and gets to the 800s, 900s or end of table, another request is triggered to fetch the next 1,000 rows - kinda similar to a Twitter feed where the data gets loaded once you scrolld down.What would the events be to trigger the call for the next set of data or is there another way to make this happen?Max
Post
Replies
Boosts
Views
Activity
Hi,Is there a way to navigate to another view after tapping a row WITHOUT using NavigationLink (see here why the NavigationLink gives me a headache: https://forums.developer.apple.com/thread/128454)I have tried@State private var presentDetails: Bool = falseandList(warehouseOrderController.warehouseOrders){ warehouseOrder in
OrderTableRow(warehouseOrder: warehouseOrder).onTapGesture {
print(warehouseOrder.orderRef!)
self.presentDetails = true
}.sheet(isPresented: self.$presentDetails){
WarehouseOrderView(warehouseOrder: warehouseOrder).environmentObject(self.settingStore)
}
}but that always brings the new view up as a modal while I actually want it to look like as if I had used the NavigationLink (meaning: not floating over the other view).Any ideas?Max
Hi,From my ContentView I use a NavigationLink to go to an Order Overview WarehouseOrderOverview()NavigationView{
ScrollView{
VStack{
NavigationLink(destination: WarehouseOrderOverview().environmentObject(self.settingStore).navigationBarTitle("Orders")) {
MenuButtonNavigation(title: "Order overview", color: Color.gray, icon: "doc.text.magnifyingglass").padding(.top)
}WarehouseOrderOverview:var body: some View {
List(warehouseOrderController.warehouseOrders){ warehouseOrder in
NavigationLink(destination: WarehouseOrderView(warehouseOrder: warehouseOrder).environmentObject(self.settingStore).navigationBarTitle("Details")){
OrderTableRow(warehouseOrder: warehouseOrder)
}So far so good. If I now tap a row in that view, I get to the order details view WarehouseOrderViewNavigationView{
ScrollView() {
VStack{
VStack(spacing: -25) {
HStack(spacing: -25) {
NavigationLink(destination: WarehouseOrderLinesView(warehouseOrderLines: warehouseOrderLineController.warehouseOrderLines)){
TaskSummaryView(title: "Total Lines", color: .blue, icon: "list.dash", value: warehouseOrderLineController.warehouseOrderLines.count)
}Problem is now that when I tap the TaskSummaryView, it opens the WarehouseOrderLinesView with two navigation bars on top (one going back to Orders, the other one to the Order details [too bad I cannot post a screenshot here ...])I believe the issue is that I create a new NavigationView in my WarehouseOrderView but I get an error when trying to use the NavigationLink without embedding it in a NavigationView. Or is there a better way than NavigationLink to open the view WarehouseOrderLinesView?Max
I have this code in my SwiftUI view structHStack{
Text("Direction")
Spacer()
Picker("Direction", selection: $selectorIndex) {
ForEach(0 ..< directions.count) { index in
Text(self.directions[index]).tag(index)
}
}
.pickerStyle(SegmentedPickerStyle())
}
Picker("From status", selection: $fromStatus2) {
ForEach(Self.orderStatusFromArray, id: \.self) { status in
Text(status)
}
}So far so good. If I now break it on purpose by changing line 12 toPicker("From status", selection: "025") {Xcode now indicates that there is an error on line 06Generic parameter 'S' could not be inferred
1. In call to initializer (SwiftUI.Text)Shouldn't it rather indicate that the error is on line 12 instead of 6?Max
Hi,I have this pickerPicker("From status", selection: $fromStatusSelectorIndex) {
ForEach(0 ..< orderStatusFromArray.count) { index in
Text(self.orderStatusFromArray[index]).tag(index)
}
}that is using data from this array:private var orderStatusFromArray: [String] = ["005", "010", "022", "025", "030", "035", "040", "045", "046", "047", "060"]When saving my values, I store the picker selection in UserDefaultsself.settingStore.defaults.set(self.orderStatusFromArray[self.fromStatusSelectorIndex], forKey: "view.orderHeaderFilter.fromStatus")What I don't understand: where in my code do I have to place it to set the picker to the saved default value? Let's say user saved the settings with status 025 (orderStatusFromArray[3]) - where do I explain to SwiftUI that the picker should be set to 3 when the view is loaded?Max
Hi,I have this code to change my background color based on the enum AddressTypeenum AddressType: String, CaseIterable{
case shipFrom = "1"
case shipTo = "2"
case unknown = "999"
init(type: String) {
switch type {
case "1": self = .shipFrom
case "2": self = .shipTo
default: self = .unknown
}
}
var text: String {
switch self {
case .shipFrom: return "Ship From"
case .shipTo: return "Ship To"
case .unknown: return "N/A"
}
}
}.background(addressType.self == AddressType.shipFrom ? Color.green : Color.yellow)Question is now: what do I have to do if I want my shipFrom in Color.green and my shipTo in Color.orange? I have tried adding a 2nd .background() for the shipTo but that did not work.Is there any way to work with more than 1 IF clause?Max
for Hi,I am retrieving data from a web service in an URLSession and store all the entries to an arrayself.warehouseOrders.append(warehouseOrder)The array is used in another view as data source for a List() item but now I get this error message: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.My question is: where is SwiftUI expecting me to put the operator receive(on:)) to fix this?I have kinda solved it by changing the code toDispatchQueue.main.async {
self.warehouseOrders.append(warehouseOrder)
}but I am not sure if that is the correct approach here?See https://forums.developer.apple.com/thread/128068for more details on my code - I have actually posted this already there as a reply but for some reason it still gets moderated for almost 24 hours ...Max
Hi,I just started playing around with SwiftUI and have stumbled over something: in my "regular" apps, my view controllers take care of loading data from a web service (triggered by a function called in the ViewDidLoad() part) and then hand the information over to the views.If I understand the concept of SwiftUI correctly, this whole piece of loading data is no longer managed in the View files but somewhere outside.So in my app now I have a class of WarehouseOrder and created another class called WarehouseOrderController that is responsible for loading the data from the server and storing it in an array (happens in function loadData() called by the init() of that class)@Published var warehouseOrders:[WarehouseOrder] = []From my main menu I call the View WarehouseOrderOverview via a NavigationLinkstruct WarehouseOrderOverview: View {
@EnvironmentObject var settingStore: SettingStore
var warehouseOrderController = WarehouseOrderController()
var body: some View {
List(warehouseOrderController.warehouseOrders){ warehouseOrder in
Text(warehouseOrder.orderRef)
}
}
}What I don't get is that when I start the app, it is triggering the init() of WarehouseOrderController already when I am in the main menu. How can I change it that the data only gets loaded when I actally trigger the NavigationLink to WarehouseOrderOverview?Max