【问题标题】:IOS App Crash when show keyboard after change binding inside sheet更改工作表内的绑定后显示键盘时 IOS 应用程序崩溃
【发布时间】:2021-07-24 14:36:53
【问题描述】:

这是我的 swiftui 代码,当我通过单击按钮更改工作表内的 tradingMode 时,在 ContentView => 应用程序崩溃后显示键盘。请帮帮我,谢谢!

枚举交易模式 { 案例衍生品、股票 }

struct ContentView: View {
    @State var tradingMode : TradingMode = TradingMode.Equities
    @State var isShowSecondView = false
    
    var body: some View {
        VStack(content: {
            Button("show second view") {
                isShowSecondView.toggle()
            }
            TabView {
                switch tradingMode {
                case .Equities:
                    VStack(content: {
                        Text("Tab 1 Un")
                            .padding()
                        TextField("ple", text: .constant(""))
                    })
                    .tabItem {
                        Text("tab 1")
                    }.tag(0)
                    
                case .Derivatives:
                    VStack(content: {
                        Text("Tab 1 Der")
                            .padding()
                        TextField("ple", text: .constant(""))
                    })
                    .tabItem {
                        Text("tab 1")
                    }.tag(0)
                }
                
                switch tradingMode {
                case .Equities:
                    VStack(content: {
                        Text("Tab 2 Un")
                            .padding()
                        TextField("ple", text: .constant(""))
                    })
                    .tabItem {
                        Text("tab 2")
                    }.tag(1)
                case .Derivatives:
                    VStack(content: {
                        Text("Tab 2 Der")
                            .padding()
                        TextField("ple", text: .constant(""))
                    })
                    .tabItem {
                        Text("tab 2")
                    }.tag(1)
                }
            }
            
        })
        .sheet(isPresented: $isShowSecondView, content: {
            SecondView(tradingMode: $tradingMode)
        })
       
    }
}

struct SecondView: View {
    @Environment(\.presentationMode) var presentation
    @Binding var tradingMode : TradingMode
    
    var body: some View {
        VStack(content: {
            Button("Change state") {
                if tradingMode == .Derivatives {
                    tradingMode = .Equities
                } else {
                    tradingMode = .Derivatives
                }
                self.presentation.wrappedValue.dismiss()
            }
        })
       
    }
}

这是我的错误:https://drive.google.com/file/d/18eXCmlByGqJylE_hCZbtJ4Rn0wmI0bb_/view?usp=sharing

【问题讨论】:

    标签: ios swift swiftui keyboard tabbar


    【解决方案1】:

    您的代码运行良好。 您可以尝试清理构建文件夹CMD + shift + K 或清除~/Library/Developer/Xcode/DerivedData 中的派生数据

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-10
      • 2013-03-04
      • 2011-08-17
      • 2021-11-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多