考慮這樣的 NavigationView 內的串列:
struct ContentView: View {
var body: some View {
NavigationView {
List {
Text("Shovel")
Text("Bucket")
Text("Sieve")
}.navigationTitle("Sandbox")
}
}
}
我想像這樣添加.swipeActions到串列條目的后沿:
Text("Shovel")
.swipeActions(edge: .trailing) {
Button{} label: { Image(systemName: "trash.fill") }
}

但是一旦我將串列條目嵌入到 aNavigationLink中,.swipeActions就不再起作用了。
NavigationLink(destination: Text("Shovel")) {
Text("Shovel")
.swipeActions(edge: .trailing) {
Button{} label: { Image(systemName: "trash.fill") }
}
}

現在進入問題:
為什么會這樣?我怎樣才能同時擁有這兩個功能?
謝謝你的幫助。
uj5u.com熱心網友回復:
你應該添加SwipeAction到NavigationLink這樣的:
NavigationLink(destination: Text("Shovel")) {
Text("Shovel")
}.swipeActions(edge: .trailing) {
Button{} label: { Image(systemName: "trash.fill") }
}
發生這種行為是因為滑動操作是modifier針對List Row. 當您只有Text時,它是行。
但是,當將您的內容嵌入到任何View( VStack, HStack, NavigationLink...) 中時,該父級將變為Row.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/486940.html
