使用 SwiftUI 显示错误 [英] Bug display with SwiftUI

查看:14
本文介绍了使用 SwiftUI 显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SwiftUI 应用,有时会出现显示错误.

I have a SwiftUI app where sometimes a bug in the display appears.

我有一个可以像这样显示的 NavagigationView :

I have a NavagigationView that sould display like this :

但有时在设备中它看起来像这样(页面顶部显示错误):

But sometimes in devices it appears like this(bug display at the top of the page):

我不明白这是从哪里来的.

I don't understand where this comes from.

这是该页面的代码:

struct FilesAdminView: View {
    @EnvironmentObject var session : SessionStore
    @ObservedObject var fileAdminViewModel : FileAdminViewModel = FileAdminViewModel()
    @State var showFilterPopUp : Bool = false
    
    @State var selected : Int = 0
    
    var body: some View {
        NavigationView{
            ZStack{
                VStack{
                        List(fileAdminViewModel.filesDisplay) { file in
                            
                            NavigationLink(destination: SingleFileView(singleFileViewModel: SingleFileViewModel(userId: self.session.session!.uid, file: file), selected: self.$selected)) {
                                VStack(spacing: 7){
                                    HStack{
                                        Text(file.nomDossier).font(Font.custom("Montserrat-Regular", size: 15))
                                        Spacer()
                                    }
                                    
                                
                                  
                       
                                    HStack {
                                        Spacer()
                                        Image(systemName: "circle.fill")
                                        Text("\(Constants.dicoEtatDisplay[file.etat]!)")
                                        
                                    }.font(.system(size: 12, weight: .light)).foregroundColor(Constants.dicoCouleurEtat[file.etat])
                                }
                                
                            }

                        }
                
                    }
                
                if showFilterPopUp {
                    GeometryReader{_ in
                        FilterPopUp(fileAdminViewModel: self.fileAdminViewModel, showFilterPopUp: self.$showFilterPopUp)
                    }.background(Color.black.opacity(0.65).edgesIgnoringSafeArea(.all).onTapGesture {
                        self.showFilterPopUp = false
                    })
                }
            }
            .navigationViewStyle(StackNavigationViewStyle())
            //.navigationBarHidden(false)
            .navigationBarTitle("Dossiers", displayMode: .inline)
            .navigationBarItems(leading:
                
                Image("Logo").resizable().frame(width: 100, height: 100)
                , trailing:
                HStack{
                    Button(action: {
                        self.showFilterPopUp = true
                    }) {
                        Image(systemName: "list.bullet").resizable().frame(width: 18, height: 18)
                    }
                    NavigationLink(destination: SettingsAdminView().environmentObject(self.session), label: {
                        Image(systemName: "gear").resizable().frame(width: 22 , height: 22)
                    })
                }
            )
        }.navigationViewStyle(StackNavigationViewStyle())
    }
}

推荐答案

我认为问题源于具有可变数量的组成视图的视图.具体来说,FilterPopUp"仅当 showFilterPopUp=true 时出现.试试这个或类似的方法,当 showFilterPopUp=false 时提供一个视图.

I think the problem stem from the View having a variable number of constituent views. Specifically, the "FilterPopUp" is present only when showFilterPopUp=true. Try this, or something similar, where you provide a view when showFilterPopUp=false.

            if showFilterPopUp {
                GeometryReader{_ in
                    FilterPopUp(fileAdminViewModel: self.fileAdminViewModel, showFilterPopUp: self.$showFilterPopUp)
                }.background(Color.black.opacity(0.65).edgesIgnoringSafeArea(.all).onTapGesture {
                    self.showFilterPopUp = false
                })
            } else {
                EmptyView()
            }

这篇关于使用 SwiftUI 显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆