Hi , I am new to SwiftUI and Mac/iOS concepts so am on a very steep learning curve.
If this is not the correct forum for this please let me know and I will delete and post elsewhere ...
Basically I am doing a favor for a friend and writing a simple data collection app for his iPad in Swift... it consists of a quite long list list of items to select from, each of which will have several possible values. Clicking on a "Change" button next to each item will bring up a list of possible values to choose from. So ....
The code works except that the list is displayed as an "icon" and has to be clicked to display the items to choose from ...
**How do I get the list to display automatically when instanced without having to click on the List icon ?
**
Code:
I have a list view which is called as the result of a button press:
Button(action: {
isShowingList=true
When the View is refreshed (State variable) results in the Selectable List view as follows:
struct TechReportView: View {
@State private var isShowingList = false
var body: some View {
if isShowingList { // display a selectable list
SelectableListView(selectedItem: $selectedItem,
isShowingList: $isShowingList,
items: $copyList,
)
}
else
{ // show list of items and current values}
The List View is as follows
struct SelectableListView: View {
@Binding var selectedItem: String?
@Binding var isShowingList: Bool
@Binding var items : [String]
var key : String
@Binding var toChange : String
var body: some View {
VStack()
{
NavigationView {
List(items, id: \.self) { item in
HStack {
Text(item)
Spacer()
if item == selectedItem {
Image(systemName: "checkmark")
.foregroundColor(.blue)
}
}
.contentShape(Rectangle())
.onTapGesture {
selectedItem = item
toChange = item
isShowingList = false
setSKeyData(key, selectedItem!)
}
}
.navigationTitle("Select Item")
.navigationBarItems(trailing: Button("Cancel") {
isShowingList = false
})
}
}
}
}
Topic:
UI Frameworks
SubTopic:
SwiftUI