I can't figure out how to display a the headers for a DataFrame in SwiftUI. According to this post, I am only able to display rows in SwiftUI. Or am I completely wrong? Is there a way to convert the headers from a DataFrame to an String Array [String]? e.g., dataframe.columns.map { col in col.name }
Search results for
SwiftUI List performance
50,605 results found
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi What do I define in the OnDelete to set what to delete. code: Environment(.managedObjectContext) var moc @FetchRequest(entity: Faces.entity(), sortDescriptors: [ NSSortDescriptor(keyPath: Faces.facename, ascending: true), NSSortDescriptor(keyPath: Faces.relationship, ascending: true), NSSortDescriptor(keyPath: Faces.birthday, ascending: true), ] ) var DBFaces: FetchedResults var body: some View { NavigationView { List { ForEach(DBFaces, id: .self) { face in Text((face.facename ?? “-“)”) .font(.title) .foregroundColor(.secondary) } } // foreach .ondelete ( ???? ) .padding() }//List } // NavView } // View
I recently updated my xcode and compiled my application developed in SwiftUI. The SwiftUI List started to behave different. List has Selection parameter for EditMode selection. However, now the list items are being selected and highlighted with grey highlighted color, even in a non-edit default mode. Ideally, it should only select the list item in edit mode. It is how it worked before. But now when the list item is tapped in non-edit mode, it is getting selected. Please, let me know how to make list with selection to highlight only in editmode. import SwiftUI struct ContentView: View { struct Ocean: Identifiable, Hashable { let name: String let id = UUID() } private var oceans = [ Ocean(name: Pacific), Ocean(name: Atlantic) ] @State private var multiSelection = Set() var body: some View { NavigationView { VStack { List(oceans, selection: $multiSelection) { ocean in Text(ocean.name) } .toolbar { EditButton() } } .padding(
Hi everyone, I'm experiencing some unwanted behaviour in my app on iOS 14. When tapping on a NavigationLink in a List, the Cell keeps being highlighted even when navigating back from the detail view. Only if I selected another Cell, the highlighting disappears. But therefore the other Cell is now highlighted. Is there any way to remove this behaviour? Running on iOS 13, everything was normal. The only workaround is to attach .id(UUID()) to the NavigationLink. But this will cause a flickering of all Cells when navigating back from the detail view and losing the scrolling position of the list. Thanks for any help or hints.
I'm observing a weird issue with SwiftUI Lists on macOS (they do work as expected on iOS). The problem is that the List calls the init & body of every row, even if those rows are not on screen (and might never be shown). If I replace the List with a ScrollView + LazyVStack, it does work as expected (only those rows which are going to be rendered get their init & body called). Of course, this is is not an ideal workaround because you loose the built-in benefits of using a List (mainly selection in my case). I did expect that under the hood, SwiftUI would use the same mechanism as NSTableView (which loads cells on demand). Historically I'm an iOS dev, so I'm used to cellForRowAtIndexPath coming from UITableView. Here's a quick gist demonstrating the issue: import SwiftUI @main struct SwiftUIListVSLazyVStackApp: App { let numbers = (0...100).map { $0 } var body: some Scene { WindowGroup { /* List calls the init & the body of *eve
I am trying to create SideBarList in SwiftUI using List, but I am not getting desired look. When I build my code, the Sidebar list keeps showing the scrollbar place even there is no scroll bar and no need for that. Code: import SwiftUItt struct DetailView: View { ttlet text: String tt ttvar body: some View { ttttText(text) tttttt.frame(maxWidth: .infinity, maxHeight: .infinity) tt} } struct ContentView: View { ttprivate let names = [Homer, Marge, Bart, Lisa] tt@State private var selection: String? ttvar body: some View { ttttNavigationView { ttttttList(selection: $selection) { ttttttttSection(header: Text(The Simpsons)) { ttttttttttForEach(names, id: .self) { name in ttttttttttttNavigationLink(destination: DetailView(text: name)) { ttttttttttttttText(name) tttttttttttt} tttttttttt} tttttttt} tttttt}.listStyle(SidebarListStyle()) ttttttDetailView(text: Make a selection) tttt} tt} } Using: macOS: 10.15.6 Xcode: 12.0 Swift: 5.3
I'm currently building an App using a TabView as the main navigation method. In my app I would like to build a page similar to the Top Charts in the native App Store App with two lists side by side: So far I came up with this code (simplified demo): import SwiftUI struct Demo: View { var body: some View { TabView { Tab(Main Tab, systemImage: tray.and.arrow.down.fill) { NavigationStack { HStack { List { Text(Left List) } List { Text(Right List) } } .navigationTitle(Demo) .navigationBarTitleDisplayMode(.inline) } } } } } #Preview { Demo() } However, I’m encountering a couple of issues: • Scrolling to the top of the left list doesn’t trigger the toolbar background effect, and the content overlaps with the tabs in a strange way. Scrolling to the top of the right list works as expected. • The navigation title is always hidden. I haven’t been able to find a solution to these problems. What would be the correct approach? Thank you!
I want to have a single selection in a List, holding content of a custom struct: struct ChannelInfo: Hashable { let title: String let description: String } And the view: struct JoinChannelView: View { @Binding var rooms: [ChannelInfo] @State var selectedRoom: String? var body: some View { VStack { if $rooms.isEmpty { Text(Loading...) .transition(.slide) } else { List(selection: $selectedRoom) { ForEach(rooms, id: .title) { room in Text(room.title) .font(.title) Text(room.description) .font(.subheadline) } .padding(.bottom) } } } .frame(width: 150, height: 300) } } My problem here is, that because inside the ForEach I render two Text views, both are selectable, but that's incorrect, I only want the title, the first Text to be selectable.
In SwiftUI on iOS, Lists must be in Edit Mode in order for .onMove to work. For some reason .onDelete will work even when not in Edit Mode. You can let the user specifically enter edit mode by embedding the List in a NavigationView NavigationView{ List{ ForEach(names, id: .self) {name in Text(name) }.onMove(perform: { indices, newOffset in names.move(fromOffsets: indices, toOffset: newOffset) }) }.navigationBarItems(trailing: EditButton()) } Or you can always be in Edit Mode by setting the environment variable programmatically like this: List{ ForEach(names, id: .self) {name in Text(name) }.onMove(perform: { indices, newOffset in names.move(fromOffsets: indices, toOffset: newOffset) }) }.environment(.editMode, Binding.constant(EditMode.active))
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
I have a sample test project at https://github.com/EricG-Personal/grdb_test.gitIn ContentView.swift, I currently have one list that shows all of the items in the Database.Below that, I would like another list that shows all of the unique 'names' from the test table.I am getting lost in the details between GRBD, Combine, and SwiftUI and am not sure what the code would look like to provide the second list with the data it needs from the database while using GRDBCombine.
I have a Core Data container with two entities, a Category and an Item. The Item can have one Category assigned and the Category can be assigned to many Items. What I need to do is group the items by category in a list in SwiftUI. The code below doesn't group all items by category, it only shows one item by category. How can I group all items that have the same category assigned under the same category group? Core Data Entities Category Attributes name Relationship items (Type: To Many) Item Attributes name Relationship category (Type: To One) Swiftui struct ItemsView: View { let selectedList:List @EnvironmentObject private var itemSM: ItemServiceModel var body: some View { List { ForEach(itemSM.items) { item in Section(header: Text(item.category?.name ?? )) { ForEach(itemSM.items.filter { $0.category == item.category }) { filteredItem in Text((filteredItem.name ?? )) } } } } .onAppear{ itemSM.loadItems(forList: selectedList) } } } Service Item Service Model class ItemServi
My code to show a list from a fetch that can be selected is (simplified) as follows @FetchRequest(sortDescriptors: []) private var players: FetchedResults @State private var selectedPlayerID : PlayerEntity.ID? var body: some View { NavigationSplitView { List(players, selection: $selectedPlayerID) { player in Text(player.shortName ?? ) } .navigationTitle(Players) } detail: { if let id = selectedPlayerID, let player = players.first(where: {$0.id == id}) { Text(Do Something) } } } I'm using the state variable of type ID PlayerEntity.ID? to hold the selection. However, I noticed the sample app from migrating to SwiftData (SampleTrips) is essentially doing it like this: @FetchRequest(sortDescriptors: [SortDescriptor(.startDate)]) private var trips: FetchedResults @State private var showAddTrip = false @State private var selection: Trip? @State private var path: [Trip] = [] var body: some View { NavigationSplitView { List(selection: $selection) { ForEach(trips) { trip in TripListItem(trip
There's a nasty SwiftUI bug in which a TextField disappears if placed in a HStack within a List.List { ForEach(0...200, id: .self) { index in HStack { Text(Text (index)) TextField(Test, text: .constant(TextField (index))) } }}- Screenshot: https://i.stack.imgur.com/HARDF.png- Video: https://recordit.co/X12uGct7gDThis happens when TextField is placed within a HStack / VStack / ZStack / .overlay() / .background(). It does not happen when TextField is the only child of ForEach. I have filed a bug (FB7500885) but I'm looking for ideas from the community to work around it. Here is what I've tried so far:Setting an explicit .frame() on TextFieldSetting .fixedSized() on TextFieldUsing a UITextField wrapped in a UIViewConvertible, with or without layout constraintsIs there anything else I could try?
In your code snippet you had: List { ForEach(modelData.filteredItems.filter { !$0.archived }) { item in drawItemRow(item) } } Every time SwiftUI re-renders the view, the closure runs again and you're performing that filtering on every update to the View. Apart from this being not performant, you could have unstable ids that are different every view update. I'd suggest you either pre-compute your filtered items once in an observable object.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags:
When I use the following code List { ForEach(data.items, id: .knowledgeInfo.mediaID) { item in SelectableKnowledgeListItem(knowledgeData: item, baseID: data.knowledgeBaseID, isSelectionMode: $isSelectionMode, selectedItems: $selectedItems) .KnowledgeListItemStyle() } // 添加底部加载更多 if !data.isEnd && !isRefreshing { ProgressView() .frame(maxWidth: .infinity, alignment: .center) .onAppear { self.isRefreshing = true manager.getKnowledgeList(knowledgeBaseID: data.knowledgeBaseID, completion: { self.isRefreshing = false }) } } } .animation(.interactiveSpring) .scrollContentBackground(.hidden) .environment(.defaultMinListHeaderHeight, 7) The number of Views rendered in the List remains unchanged after he adds an item to data.items (data is an ObservedObject, items is Published) at runtime.When I removed .animation(.interactiveSpring), it would be processed normally.And if I perform a delete operation after adding, it will cause a crash. *** Terminating app due to uncaught exception '
Topic:
UI Frameworks
SubTopic:
SwiftUI