首页 > 解决方案 > SwiftUI Picker 导航到 Core NavigationView 而不是调用它的 View

问题描述

我一直在绞尽脑汁想弄清楚是什么原因造成的,我假设它与 NavigationView 所在的位置有关。

要添加上下文,我有一个视图,我们将其称为 View A,其中包含 NavigationView。在视图 A 中有一个带有导航链接的工具栏,该链接调用以下代码片段所在的视图 B。当点击下面的选择器时,它会移动到一个视图以选择选择器选项,但在点击一个选项时,它会返回到视图 A 而不是视图 B。

添加包装此表单的附加 NavigationView 确实解决了问题,但不是我所说的理想,因为它添加了额外的标题栏。

//The following form contains all of the form components to compose the add MetaList View
        Form{
            
            Section {
                TextField("MetaList Name", text: $newMetaListName)
            }
            
            Section(header: Text("Description")){
                TextEditor(text: $newMetaListDescription)
            }
            
            //The following section contains the picker to determine the type of list being created
            Section {
                Picker("MetaList Type", selection: $metaListType) {
                    
                    //The following for each utilizes the Enum detailed in MetaListModels to create an item for each case
                    ForEach(MetaListTypes.allCases) { metaListType in
                        Text(metaListType.name).tag(metaListType)
                    }
                }
            }
            
            //The following is a placeholder section for future tags
            Section(header: Text("Tags")){
                
            }
            
            Button(action: {
                if newMetaListName.isEmpty {
                    metaListNameBlank = true
                } else {
                    metaListNameBlank = false
                    addMetaList()
                }
            }) {
                Text("Submit")
            }
#if os(iOS)
            .alert("Name Field Cannot Be Left Blank", isPresented: $metaListNameBlank) {
                Button("OK", role: .cancel) { }
                
            }
#endif
            .padding()
        }
        .navigationTitle("Create New MetaList")
    }

我非常感谢任何帮助,因为我不太确定还能尝试什么。

标签: swiftuiswiftui-navigationviewswiftui-picker

解决方案


推荐阅读