导航样式选择器不显示选择,不会触发onReceive

时间:2020-07-01 15:52:11

标签: swiftui pickerview

我尝试了许多选项,但没有一个按预期运行。该应用程序应显示一个企业列表,然后显示选择了哪个。该列表显示正确,我可以选择一家公司,该视图关闭并返回上一个视图,但是没有显示任何内容,也没有触发任何内容。如您所见,我注释掉了onReceive并更改了我希望返回的内容,并且行为没有改变。然后,我将ForEach更改为使用字符串和id:.self的静态数组,但没有更好的运气。

我在Xcode输出窗口中收到以下错误。

2020-07-01 08:35:29.790369-0700 SampleCode[33626:26142041] [UIContextMenuInteraction] Attempting -[UIContextMenuInteraction dismissMenu], when not in an active state. This is a client error most often caused by calling dismiss more than once during a given lifecycle. (<_UIVariableGestureContextMenuInteraction: 0x600002211500>)

代码紧随其后...任何建议都将受到欢迎。

@FetchRequest(entity: Business.entity(),
                  sortDescriptors: [NSSortDescriptor(key: "name", ascending: true)],
                  animation: .spring()) var businesses: FetchedResults<Business>
    
    @State private var bus = ""
    @State private var bb = 0

    
    //@ObservedObject var lm = LocationManager()
    
    var body: some View
    {
        return NavigationView
        {
            VStack
            {
                
                if businesses.count > 0
                {
                    Form
                    {
                        Section(header: Text("Participanting Restaurants"))
                        {
                            //Picker("", selection: $bus)
                            Picker(selection: $bb, label: Text("Name"))
                            {
                                ForEach (businesses, id: \.businessid)
                                { business in
                                    Text(business.name!) // .tag(business.businessid)
                                }
                            }
                            /*.onReceive([self.bb].publisher.first())
                            { (value) in
                                print(bb)
                            }*/
                        }
                    }
                }
            }.navigationBarTitle(Text("Login"), displayMode: .inline)
        }
    }
    
 

0 个答案:

没有答案