swiftui-list

How to change complex data source in swiftUI List

我的未来我决定 提交于 2020-07-09 12:34:17
问题 App crash when I change data source like I tap “change data” button in APIView or delete item in QueryParametersView.list console log: This class 'SwiftUI.AccessibilityNode' is not a known serializable element and returning it as an accessibility element may lead to crashes Fatal error: Index out of range: file /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1103.8.25.8/swift/stdlib/public/core/ContiguousArrayBuffer.swift, line 444 class URLComponentsModel:

Adding shapes in List row of SwiftUI

大兔子大兔子 提交于 2020-07-09 08:38:23
问题 I am trying to create a List View where rows looks like this: However, I am unable to align the Circle on the leading side. Tried using Spacer() , HStack within VStack , it just doesn't work. Here's my code and its output. struct PeopleView: View { let people = ["Adam", "James"] var body: some View { NavigationView { List { ForEach(people, id: \.self) { person in HStack { Circle() VStack { Text("\(person)") } } } } .navigationBarTitle("People", displayMode: .inline) } } } 回答1: Actually you

Adding shapes in List row of SwiftUI

╄→гoц情女王★ 提交于 2020-07-09 08:37:33
问题 I am trying to create a List View where rows looks like this: However, I am unable to align the Circle on the leading side. Tried using Spacer() , HStack within VStack , it just doesn't work. Here's my code and its output. struct PeopleView: View { let people = ["Adam", "James"] var body: some View { NavigationView { List { ForEach(people, id: \.self) { person in HStack { Circle() VStack { Text("\(person)") } } } } .navigationBarTitle("People", displayMode: .inline) } } } 回答1: Actually you

Unwanted animation when moving items in SwiftUI list

為{幸葍}努か 提交于 2020-07-06 11:54:31
问题 I have a SwiftUI List like in the example code below. struct ContentView: View { @State var numbers = ["1", "2", "3"] @State var editMode = EditMode.inactive var body: some View { NavigationView { List { ForEach(numbers, id: \.self) { number in Text(number) } .onMove { self.numbers.move(fromOffsets: $0, toOffset: $1) } } .navigationBarItems(trailing: EditButton()) } } } When I enter edit mode and move the item one position up the strange animation happens after I drop the item (see the gif

SwiftUI automatically scroll to bottom in ScrollView (Bottom first)

柔情痞子 提交于 2020-07-06 10:16:11
问题 My problem is that i have (in SwiftUI) a ScrollView with an foreach inside. Know when the foreach loads all of my entries i want that the last entry is focused. I did some google research, but i didn't find any answer. ScrollView { VStack { ForEach (0..<self.entries.count) { index in Group { Text(self.entries[index].getName()) } } } } 回答1: Solution for iOS14 with ScrollViewReader in iOS14 SwiftUI gains a new ability. To be able to scroll in a ScrollView up to a particular location. There is a

SwiftUI automatically scroll to bottom in ScrollView (Bottom first)

一笑奈何 提交于 2020-07-06 10:15:55
问题 My problem is that i have (in SwiftUI) a ScrollView with an foreach inside. Know when the foreach loads all of my entries i want that the last entry is focused. I did some google research, but i didn't find any answer. ScrollView { VStack { ForEach (0..<self.entries.count) { index in Group { Text(self.entries[index].getName()) } } } } 回答1: Solution for iOS14 with ScrollViewReader in iOS14 SwiftUI gains a new ability. To be able to scroll in a ScrollView up to a particular location. There is a

SwiftUI automatically scroll to bottom in ScrollView (Bottom first)

我的未来我决定 提交于 2020-07-06 10:15:38
问题 My problem is that i have (in SwiftUI) a ScrollView with an foreach inside. Know when the foreach loads all of my entries i want that the last entry is focused. I did some google research, but i didn't find any answer. ScrollView { VStack { ForEach (0..<self.entries.count) { index in Group { Text(self.entries[index].getName()) } } } } 回答1: Solution for iOS14 with ScrollViewReader in iOS14 SwiftUI gains a new ability. To be able to scroll in a ScrollView up to a particular location. There is a

Reduce Form spacing between sections SwiftUI

坚强是说给别人听的谎言 提交于 2020-06-28 03:43:21
问题 I'm trying to make a notes app with SwiftUI and I'd like to show the notes similar to the Apollo Reddit app does. The way it shows the post isn't anything special, it just shows the posts using an interface similar to a list with GroupedListStyle() , but with less spacing between sections. I've tried a lot of tricks to reduce this spacing, but none of them seems to work. TL;DR I've got this : And I want this : Any help is appreciated. Thanks in advance! Here's my code : import SwiftUI struct

Position view relative to a another centered view

折月煮酒 提交于 2020-06-17 08:03:45
问题 Hello SwiftUI community, I'm trying to do something that's probably easy to do but I'm stuck on it since hours. In a list, I'd like to have items composed of: A text centered horizontaly (a number) A text on the left of the number A text on the right of the number I've tried many things (alignments, aligmentguides, GeometryReader....) but didn't find the way to achieve the result above. Does anyone has an example to help me? Thanks 🙏🏻 回答1: Here is possible solution. Tested with Xcode 11.4 /

SwiftUI macOS Scroll a List With Arrow Keys While a TextField is Active

依然范特西╮ 提交于 2020-06-12 15:23:00
问题 I'd like to use a SwiftUI TextField and a SwiftUI List to render a "search box" above a list of items. Something roughly like the search box available in Safari's Help menu item...which provides a search box where you can always enter text while simultaneously browsing through the list of results using the up and down arrow keys. I've played with onMoveCommand, focusable, and adjustments to the "parent" NSWindow , but haven't found a clear and obvious way for the TextField to constantly