I have a view where the user can configure which train lines are shown on a map. I'm having an issue where the list row background is ignored for all of the cells which are selected. Here is code that I am using: struct MapConfigurator: View { @Binding var routes: Set<Route> var body: some View { List(selection: $routes) { Section(header: Text(Show)) { ForEach(Route.allCases, id: .self) { route in Text(route.name) .foregroundColor(route.textColor) .listRowBackground(route.color) .tag(route) } } } .navigationBarTitle(Configure Map) .listStyle(GroupedListStyle()) .environment(.editMode, .constant(.active)) } } struct MapConfigurator_Previews: PreviewProvider { static var previews: some View { NavigationView { MapConfigurator(routes: .constant([.red, .green, .blue])) } } }
Search results for
SwiftUI List performance
50,605 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Thanks! And how would I manage that in SwiftUI with a List element?
Topic:
UI Frameworks
SubTopic:
UIKit
Tags:
I have a SwiftUI app with a List displaying an array of model objects. When the user taps a list item we see its detail view. I want to add previous and next buttons to my detail view, but I'm not sure what needs to happen when previous/next are tapped. (see code below for what I'm looking to do) My first thought is to make the model variable in the DetailView be a binding, but I'm not sure how this would tie in with the NavigationLink 'stuff' any/all suggestions appreciated. thanks! class Model: Identifiable { var modelValue: Int init(modelValue: Int) { self.modelValue = modelValue } static let testData = [Model(modelValue: 3), Model(modelValue: 7), Model(modelValue: 31)] } class ModelManager { static let shared = ModelManager() let modelList = Model.testData func previous(for model: Model) - Model? { if let index = modelList.firstIndex(where: {$0.modelValue == model.modelValue}) { if index 0 { return modelList[index - 1] } } return nil } func next(for model: Model) - Model? { if l
I created a List for a settings menu with two sections where you can reorder/add/remove a set of pages. It should work similar to Apple's Today Widget editing menu where you can add and reorder items.Connector class code snippet:class SettingsConnector: ObservableObject { enum DetailsPage { case page1 case page2 case page3 func printed() -> String { switch self { case .page1: return Page 1 case .page2: return Page 2 case .page3: return Page 3 } } } @Published var detailsPages: [DetailsPage] = [.page1, .page2] @Published var hiddenDetailsPages: [DetailsPage] = [.page3] }SwiftUI code snippet:List { Section { ForEach(self.connector.detailsPages, id: .self) { page in HStack(spacing: 0) { Text((page.printed())) Spacer() } } .onMove { (source, destination) in self.connector.detailsPages.move(fromOffsets: source, toOffset: destination) } .onDelete { (rows) in rows.forEach { (i) in let page: SettingsConnector.DetailsPage = self.connector.detailsPages[i] self.connector.detailsPages.remove(at: i) s
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.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I have the following code written using SwiftUI 2.0, Xcode 12.0 beta 5 on OS 11 beta 5. struct ContentView: View { var body: some View { GeometryReader { geometry in List { ForEach(data, id: .id) { article in ArticleCell(article: article) } .frame(width: geometry.size.width) .listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0)) } .listStyle(PlainListStyle()) } } } struct Article: Identifiable { let id: String let title: String let description: String } let data = [ Article( id: UUID().uuidString, title: Title 1, description: NASA has awarded the Strategic Research and Analysis, Communications, and Exhibits Services (SRACES) contract to Media Fusion LLC of Huntsville, Alabama, to provide comprehensive strategic research and analysis, communications, and exhibits services at the agency’s Marshall Space Flight Center in Huntsville, Alabama. ), Article( id: UUID().uuidString, title: Title 2, description: Girl Scouts from across the nation will pose questions next week to NASA astrona
You should attach an alert to each item in List. See details here: https://stackoverflow.com/questions/62720595/how-to-add-confirmation-to-ondelete-of-list-in-swiftui
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
SWIFTUI List object .onTapGesture or Click event not setting values ?. Bug or issue with way .sheet works? On list object .onTapGesture / selection of the row I wanted send the Index /value to another view via .Sheet option And 90% of the time I get 0 (wrong value) help / guide , a newbie Code snippets for main view & popup view below //Main view with list object: import SwiftUI struct SwiftUIView_Sheet_Test_Main: View { let workflow_trn_data:[workflow_transaction_data] = [ .init(mst_rec_id: 100, work_task: Task 100), .init(mst_rec_id: 101, work_task: Task 101) ] @State private var selected_Mst_record:Int32 = 0 @State private var isPopupSheetActive:Bool = false var body: some View { Text(Sheet Test Main View) NavigationStack{ List() { ForEach(0..
Topic:
UI Frameworks
SubTopic:
SwiftUI
Use the task(priority:_:) modifier. It allows you to perform an asynchronous task with a lifetime that matches that of the view. Discover concurrency in SwiftUI dives deep into how you can use Swift's concurrency features in your SwiftUI app. It's a great resource you should review.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
func perform() async throws What are the abnormal errors thrown by the above ? Can you provide a clear list? error:Error Domain=com.apple.MatterSupport Code=1 (null) Where can I find the error information in the document? MatterSupport / MatterAddDeviceRequest / perform() What does this error mean: Error Domain=com.apple.MatterSupport Code=1
Thanks, i guess SwiftUI lists also can’t do this yet? Multi select drag and drop in the same list for mass re-ordering.
Topic:
UI Frameworks
SubTopic:
SwiftUI
I'm not sure if there's a built-in way of doing it, but you can add swipeActions to a row, then perform an action based on the button tapped. var body: some View { List { ForEach(etc.) { element in RowView(rowData: element) .swipeActions(edge: .leading, allowsFullSwipe: false) { MySwipeButtonsView(rowData: element) } } } } struct MySwipeButtonsView: View { var rowData: RowDetails // The type for the row data var body: some View { Button { insertRow() // Insert a row above/below in your array, and SwiftUI should redraw the list if you've set up an observable model etc. } label: { Label(, systemImage: plus) .symbolRenderingMode(.palette) .labelStyle(.iconOnly) .tint(Color.green) .foregroundStyle(Color.white) } } }
Topic:
UI Frameworks
SubTopic:
SwiftUI
This also happens in SwiftUI when a project is localized to a Single language (Arabic) or set it as the default language, in the List view, and the direction of the list remains from left to right.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
This would depend on how you manage dependcies in your View. You would want to structure your view so that it depends on only the data it needs to display and not your entire dictionary. This is because Views form a graph and SwiftUI looks at depencies when evaulating a code. I would suggest you checkout Demystify SwiftUI performance session, it dives into how SwiftUI evaluates your views.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Hi, In your SwiftUI View .onOpenURL(perform: { (url) in Should be called in response to the .widgetURL(entry.character.url) set on your Widget's SwiftUI view. You can see the Emoji Rangers sample project for additional information Rico WWDR - DTS - Software Engineer
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: