Post

Replies

Boosts

Views

Activity

SwiftUI Table Limit of Columns?
I am trying to build a Table using SwiftUI that has 14 columns. If I enter that many TableColumns under Table, I get the "The compiler is unable to type-check..." error. In fact, I get that error until I cut it back to 10 columns. My Columns all look something like this, with different name and value paths, of course:             TableColumn("Loc", value: \.location) I have seen that the way around this error is to break up the expression into something simpler. But I can't figure out how to simplify the number of columns. Any ideas? Thanks, Don
4
2
1.8k
Mar ’22
Navigation, sheet, or overlay?
Hi, I'm working on a SwiftUI Table based app for macOS (primarily, maybe other devices if I can make it work). My data consists of 14 fields, and since the SwiftUI ViewBuilder can only deal with 10 items, I have to show a subset. But I want to make them all available to users. Likewise, it does not appear that SwiftUI tables allow live editing of the data, so I will also need a way to provide that feature. But this question deals with the display of all the data. I have tried using sheets and Navigation, but I am not happy with the results to date. I created a column which has an HStack with buttons for viewing and editing. To create a sheet, I used this code: TableColumn("View/Edit") { channel in                  HStack {                      Button {                          showingViewSheet.toggle()                     } label: {                         Label("", systemImage: "eye")                     }                 .sheet(isPresented:$showingViewSheet) {                     VStack {                         ChannelDetailView(channel: channel)                         Spacer()                         Button("Dismiss") {                             showingViewSheet.toggle()                         }                     }                     .padding()                 }                     Button {                         editChannel(channel: channel)                     } label: {                         Label("", systemImage: "pencil")                     }                 }              } The result would be acceptable: But there is a big problem. It is showing the info for the zeroth item in the array. If I click on the eye in the second row, the zeroth info still is displayed. There is also a weird artifact that on dismissal, the sheet vanishes, then reappears, then finally vanishes. So, the Navigation code looks like this: var body: some View {         NavigationView {             Table(channels, selection: $selection, sortOrder: $sortOrder) { . . .                 TableColumn("View/Edit") { channel in                      HStack {                          NavigationLink(destination: ChannelDetailView(channel: channel)) {                              Label("", systemImage: "eye")                          } . . . Initially the result of this puzzled me: But after some thought, I realized that NavigationView was stuffing my entire table into a sidebar. When I resized the sidebar, I got something like what I want: This at least displayed the detail correctly. But it is not what I want. The detail is not reflective of the document in total, so should not have the title bar over it. I' thinking overlay or ZStack, but I thought I would ask to see if I am doing something wrong with the sheet, or if there is a way to make Navigation work the way I want to, or if there is some other best practice I am missing. Many thanks! Don Carlile
2
0
1.8k
Mar ’22