swiftui-list

What is the right way to present data from Realm in SwiftUI List

蓝咒 提交于 2021-02-05 07:00:34
问题 I’m trying to fetch all of the items from Realm and display them in a SwiftUI List but I keep getting an error. In a UIKit/Realm application, I would just create a Results variable to store all of the items from Realm then, I would fetch items in the viewDidLoad method and assign them to the variable. I'm trying to do the same thing in SwiftUI but I'm not sure how to structure my code, I keep getting an error saying that my Realm model should conform to the StringProtocol , I'm pretty sure

How do you implement list paging in SwiftUI or infinite list view?

核能气质少年 提交于 2021-02-04 19:42:52
问题 I want help on how to implement infinite list scrolling or paging list in SwiftUI.Thanks in advance 回答1: Your best bet is to use .onAppear and calculate if it's time to fetch your next page. This is a contrived example because typically you're hitting a network or disk which is much slower than this, but it will give you an idea. Tune getNextPageIfNecessary(_:) for your particular use-case. @State var rows: [String] = Array(repeating: "Item", count: 20) var body: some View { List(0..<rows

SwiftUI .onDelete throws Fatal Error: Index out of range

£可爱£侵袭症+ 提交于 2021-01-29 22:33:49
问题 I have list of Account s that each of them has a detail page and they are connected through @Binding in the AccountDetailView . Current code work well, updates are fine. No problem at all. However when I added the onDelete modifier to the ForEach below and tried swipe to delete gesture in app, it crashes and says Fatal Error: Index out of range twice. I made some search and learned that ForEach somehow does not get notified -or ignores it, idk much detail- and looks for the last index of the

List Sections do not work correctly if .navigationBarItems is present

故事扮演 提交于 2021-01-29 06:36:40
问题 How to have both a button in navigation bar and a list with sections? Here is a code with .navigationBarItems : struct AllMatchesView: View { @Environment(\.managedObjectContext) var moc @State var events = EventData() var body: some View { NavigationView { List{ ForEach(events.sections) { section in Section(header: Text(section.title)) { ForEach(section.matches) { match in Text("Row") } } .navigationBarTitle("Title") .navigationBarItems(trailing: NavigationLink(destination: AddMatchView()

In SwiftUI List View refresh triggered whenever underlying datasource of list is updated from a view far away in hierarchy

霸气de小男生 提交于 2021-01-27 17:28:54
问题 I am trying to write a "Single View App" in SwiftUI. The main design is very simple. I have a list of items (say Expense) which I am displaying in main view in NavigationView -> List. List View Source Code import SwiftUI struct AmountBasedModifier : ViewModifier{ var amount: Int func body(content: Content) -> some View { if amount <= 10{ return content.foregroundColor(Color.green) } else if amount <= 100{ return content.foregroundColor(Color.blue) } else { return content.foregroundColor(Color

In SwiftUI List View refresh triggered whenever underlying datasource of list is updated from a view far away in hierarchy

走远了吗. 提交于 2021-01-27 17:01:36
问题 I am trying to write a "Single View App" in SwiftUI. The main design is very simple. I have a list of items (say Expense) which I am displaying in main view in NavigationView -> List. List View Source Code import SwiftUI struct AmountBasedModifier : ViewModifier{ var amount: Int func body(content: Content) -> some View { if amount <= 10{ return content.foregroundColor(Color.green) } else if amount <= 100{ return content.foregroundColor(Color.blue) } else { return content.foregroundColor(Color

SwiftUI overlay blocking List scroll events

青春壹個敷衍的年華 提交于 2021-01-27 13:18:49
问题 I'd like to put a semi-transparent image overlay on top of the list in SwiftUI. I've tried the code like this: struct ContentView: View { var body: some View { List { Text("first") Text("second") Text("third") } .overlay( Image(systemName: "hifispeaker") .resizable() .frame(width: 200, height: 200) .opacity(0.15) ) } } It looks as expected, but if you place your finger within image boundaries the scrolling of the list doesn't work (if you try to scroll outside the image it works fine) I've

SwiftUI - Dynamic List filtering animation flies to right side when data source is empty

会有一股神秘感。 提交于 2021-01-27 06:19:20
问题 I have a List that gets data from my people array and displays their names. I'm also filtering the list so that it only shows the names that contain the text field's text, which is searchText . Here's my code: struct Person: Identifiable { let id = UUID() /// required for the List var name = "" } struct ContentView: View { @State var searchText = "" var people = [ /// the data source Person(name: "Alex"), Person(name: "Ally"), Person(name: "Allie"), Person(name: "Bob"), Person(name: "Tim"),

How to remove bottom/top item padding from SwiftUI List in Mac OS

蓝咒 提交于 2021-01-05 07:07:47
问题 I am having a hard time removing all padding from my cells in MacOS using SwiftUI. I can't seem to be able to do it even in Apple's Code! https://developer.apple.com/tutorials/swiftui/creating-a-macos-app For example, inside the LandMarkList of the MacLandmarks folder in Xcode, I have put a .listRowInsets(EdgeInsets()) at the end of the forEach so that the code looks like this: struct LandmarkList: View { @EnvironmentObject private var userData: UserData @Binding var selectedLandmark:

SWiftUI anchorPreference inside List

﹥>﹥吖頭↗ 提交于 2021-01-04 06:06:32
问题 I'm using anchorPreferences to set the height of GeometryReader to fit the height of its content. The issue I'm experiencing is, after scrolling up and down the List a few times, the app freezes, the design gets messy, and I get the following message in the console: Bound preference CGFloatPreferenceKey tried to update multiple times per frame. Any ideas how I can fix this? IMPORTANT NOTE: I've simplified my design as much as I could. Here is the code: struct ListAndPreferences: View { var