Post

Replies

Boosts

Views

Activity

Fixing offset in two axis ScrollView
Hi, I wrote the code below to demonstrate an issue I cannot handle, since I am very new to swiftui struct Cell: Identifiable { var id: UUID = UUID() var i: Int = 0 init(i: Int) { self.i = i } } struct ContentView: View { var columns: [GridItem] = [GridItem](repeating: GridItem(.fixed(40), spacing: 5), count: 60) var cells: [Cell] = [] init() { cells.removeAll() for i in 0..<180 { cells.append(Cell(i:i)) } } var body: some View { ScrollView([.horizontal, .vertical]) { LazyVGrid(columns: columns, spacing: 5) { ForEach(cells) { cell in ButtonView(cell: cell) } } } } } struct ButtonView: View { var cell: Cell @State var popOver: Bool = false var body: some View { Button { popOver.toggle() } label: { Text("\(cell.i)") } .popover(isPresented: $popOver, content: { Text("Information line of button \(cell.i)").padding() }) } } #Preview { ContentView() } Running the code above, button clicks are not always work
3
0
333
Apr ’24
Understanding the swift language and its documentation
Hi, I am inexperienced hobbyist programmer in the Xcode environment and the swift language. I have a very basic question: I read the documentation about one of the NavigationSplitView initializers: init(sidebar: () -> Sidebar, detail: () -> Detail) I created two basic views the SidebarView and the DetailsView. The following code, use the views above as parameters but gives errors, and I cannot understand why. import SwiftUI struct ContentView: View { var body: some View { NavigationSplitView(sidebar: SidebarView(), detail: DetailsView()) } } #Preview { ContentView() } I am interested to understand how the swift language works, and how to implement the documentation of swiftUI in real code. Is there any way to use the views as parameters and not in brackets? import SwiftUI struct ContentView: View { var body: some View { NavigationSplitView { SidebarView() } detail: { DetailsView() } } } #Preview { ContentView() }
2
0
292
Dec ’23