Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加了RefreshHeader后,当刷新数据后,无法跳转界面,如果点其它Tab后,会从其它Tap NavigationLink, 如果不加RefreshHeader,则可以跳转 #11

Open
WXRLCZ opened this issue Feb 25, 2023 · 0 comments

Comments

@WXRLCZ
Copy link

WXRLCZ commented Feb 25, 2023

无法跳转的代码

   NavigationLink {

                        DeviceDetailView()
                            .environmentObject(record)
                            .onAppear {
                                self.srecord = record
                            }

                    } label: {

                        DeviceRow().environmentObject(record)


                    }       

贴完整代码如下 :
VStack{
ScrollView {

        if records.count > 0 {
            
            RefreshHeader(refreshing: $headerRefreshing, action: {
                self.postEleList(refreshType: .refresh)
            }) { progress in
                if self.headerRefreshing {
                    SimpleRefreshingView()
                } else {
                    SimplePullToRefreshView(progress: progress)
                }
            }
            
        }
           
        
        if records.count > 0 {
            
            LazyVStack(spacing: 0) {
                
                ForEach(records,id:\.self) { record in
                    

                    NavigationLink {

                        DeviceDetailView()
                            .environmentObject(record)
                            .onAppear {
                                self.srecord = record
                            }

                    } label: {

                        DeviceRow().environmentObject(record)


                    }
                
                    
                }
                
            }
            .padding(.vertical)

            
        }else {
            DeviceLearnNoDataView()
        }
        
        if records.count > 0 {
            RefreshFooter(refreshing: $footerRefreshing, action: {
                self.postEleList(refreshType: .more)
            }) {
                if self.noMore {
                    Text("已加载完毕")
                        .modifier(WeiXiuLCContentFontModifier())
                        .padding()
                } else {
                    SimpleRefreshingView()
                        .padding()
                }
            }
            .noMore(noMore)
            .preload(offset: 50)
        }
        
    }
    .enableRefresh()
}

func postEleList(refreshType: RequestType){
    UtilsMacroSwift.show()
    let eleN = self.searchModel.eleName
    let eleAdd = self.searchModel.eleAddress
    eleVM.postEleList(refreshType: refreshType, status: status,eleName: eleN,eleAddress: eleAdd) {
        
        self.handRefresh(refreshType: refreshType)
        
    } failure: { str in
        
        self.handRefresh(refreshType: refreshType)
        
        UtilsMacroSwift.makeToast(str)
    }
    
}

func handRefresh(refreshType :RequestType?){
    DispatchQueue.main.async {
        UtilsMacroSwift.HUDDismiss()
        if refreshType == .refresh {
            self.headerRefreshing = false
            
        }
        else if refreshType == .more {
            self.footerRefreshing = false
            
        }
        else {
            self.headerRefreshing = false
            self.footerRefreshing = false
        }
        
        self.noMore = eleVM.isEnd
    }
}

我的工程结构如下 :
NavigationView{

        TabView(selection: $selection) {
            
            TongJiView()
                .tabItem {
                        
                    Label("统计", image: self.selection == .tongJi ? "tab_daiban_selected" : "tab_daiban_default")
                        
                }
                .tag(Tab.tongJi)
            
            DaiBanView()
                .tabItem {
                        
                    Label("待办", image: self.selection == .daiBan ? "tab_daiban_selected" : "tab_daiban_default")
                        
                }
                .tag(Tab.daiBan)
                
            
            
            DianTiView()
                .tabItem {
                    Label("电梯", image: self.selection == .dianTi ? "tab_dianti_selected" : "tab_dianti_default")
                }
                .tag(Tab.dianTi)
            
            
            MineView()
                .tabItem {
                    Label("我的", image: self.selection == .mine ? "tab_mine_selected" : "tab_mine_default")
                }
                .tag(Tab.mine)
            
        }
        .navigationTitle(selection.naviTitle)
        .navigationBarTitleDisplayMode(.inline)
        .navigationBarItems(
            leading:
                
                HStack {
                    if selection == .tongJi, let _ = accountVM.accountLoginModel?.token?.token {
                        HStack {
                           Text(tipStr)
                                .foregroundColor(.white)
                        }
                    }
                    
                },trailing: HStack {
                    if selection == .dianTi || selection == .daiBan {
                        Button(action: {
                           
                            NotificationCenter.default.post(name: .init(rawValue: kSearchNaviBarClickNotifiName), object: selection)
                            
                        }, label: {
   
                            Image("navi_search")
                            
                        })

                    }

                }
                
        )
        
        
    }
@WXRLCZ WXRLCZ changed the title 加了RefreshHeader后,当刷新数据后,无法跳转界面,如果点其它Tab后,会从其它Tap NavigationLink 加了RefreshHeader后,当刷新数据后,无法跳转界面,如果点其它Tab后,会从其它Tap NavigationLink, 如果不加RefreshHeader,则可以跳转 Feb 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant