我在顯示行串列的作業表上遇到了這個問題,因此當按下一行時,應用程式應該轉到另一個視圖/螢屏(C 視圖)并且作業表已關閉,這種情況正在發生,但視圖/螢屏是一推就彈出來。
iOS 15
視圖 A:
import SwiftUI
struct A: View {
@State private var showNewMessage = false
@State private var showChatView = false
var body: some View {
ZStack(alignment: .bottomTrailing){
NavigationLink(
destination: C(),
isActive: $showChatView,
label: {})
//NavigationLink(destination: EmptyView(), label: {})
ScrollView {
VStack(alignment: .leading) {
ForEach( 1...10, id: \.self){_ in
NavigationLink(
destination: C(),
label: {
ChatView()
})
}
}
}
Button(action: {
//showNewMessage.toggle()
showNewMessage = true
}, label: {
Image(systemName: "pencil")
.resizable()
.scaledToFit()
.frame(width: 24, height: 24)
})
.padding()
.foregroundColor(Color.white)
.background(Color.blue)
.clipShape(Circle())
.sheet(isPresented: $showNewMessage, onDismiss: test, content: {
B(showChatView: $showChatView, closeView: $showNewMessage)
}).navigationViewStyle(StackNavigationViewStyle())
}
.padding(.horizontal)
}
func test(){
print("Epale Debug: showChatValue: \(showChatView)")
}
func toggle(){
showChatView.toggle()
}
}
視圖 B:
import SwiftUI
struct B: View {
@Binding var showChatView: Bool
@Binding var closeView: Bool
//@Environment(\.presentationMode) var mode
var body: some View {
Button(action: {
//showChatView.toggle()
showChatView = true
closeView = false
print("Epale Debug: showChatValue: \(showChatView)")
//mode.wrappedValue.dismiss()
}, label: {
Text("Toggle")
})
}
}
PS:View C 只是另一個視圖,我已經在根檔案中的 NavigationView 中添加了 navigationViewStyle(StackNavigationViewStyle()) 屬性。
uj5u.com熱心網友回復:
一段時間后更改第二個狀態以有機會完成作業表關閉,例如
Button(action: {
closeView = false
print("Epale Debug: showChatValue: \(showChatView)")
DispatchQueue.main.asyncAfter(deadline: .now() 0.3) {
showChatView = true // << here !!
}
}, label: {
Text("Toggle")
})
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/364249.html