问题描述
当我单击左箭头时,它应该关闭该视图,但是只有UI会响应,因为单击了该按钮并且未关闭NavigationLink推送的视图...
由另一个NavigationLink在另一个视图中推入的同一视图可以很好地工作,但是当由该NavigationLink推入时,我单击左箭头,则只有20倍的视图关闭了该视图。又是SwiftUI中的错误吗?有解决方法吗?
import SwiftUI
import Firebase
import struct Kingfisher.KFImage
struct SearchView: View {
@Environment(\.presentationMode) var presentation
@State var typedSearchValue = ""
@State var createNewPost = false
@State var showMessaging = false
@EnvironmentObject var userInfo : UserData
@Binding var switchTab: Int
@State var text : String = ""
@State var foundUsers: [FetchedUser] = []
@State var showAccount = false
@State var fetchedUser = FetchedUser()
var body: some View {
NavigationView {
ZStack{
// navigate to that user's profile << the problem navlink
NavigationLink(destination:
UserAccountView(fetchedUser: self.$fetchedUser,showAccount: self.$showAccount)
.environmentObject(self.userInfo)
.environmentObject(FetchFFFObservable()),isActive: self.$showAccount
){
EmptyView()
}.isDetailLink(false)
//...
NavigationLink(destination:
MessagingMainView(showMessaging: self.$showMessaging)
.environmentObject(UserData())
.environmentObject(MainObservable()),isActive: self.$showMessaging
){
Text("")
}
vstack(spacing: 0) {
SearchBarMsg(text: $text,foundUsers: $foundUsers)
.environmentObject(userInfo)
.padding(.horizontal)
vstack{
if text != ""{
List(foundUsers,id: \.username){ user in
FetchedUserCellView(user: user)
.environmentObject(self.userInfo)
.onTapGesture {
self.fetchedUser = user
self.showAccount = true
}
}
}else{
//....
}
}
}
.navigationBarColor(.titleBarColor)
}
}.navigationViewStyle(StackNavigationViewStyle())
}
}
导航到该视图,尽管UI做出响应,但NavigationItems中的按钮不起作用
struct UserAccountView: View {
@Environment(\.presentationMode) var presentation
//...
@Binding var showAccount : Bool
var body: some View {
vstack {
//.....
}
.navigationBarColor(.titleBarColor)
.navigationBarTitle(Text(fetchedUser.username),displayMode: .inline)
.navigationBarItems(leading: Button(action: {
//this button doesn't work!
self.showAccount = false
},label: {
Image(systemName: "arrow.left")
.resizable()
.frame(width: 20,height: 15)
})).accentColor(.white)
)
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)