我們可以使用 on change 按鈕在同一視圖中顯示串列嗎?我是初學者
struct ViewMe: View {
var body: some View {
Button (action:{
},label:{
Text("Search")
})
// can we do on change here to appear a list
}
}
uj5u.com熱心網友回復:
根據你給我的資訊,這里有一些代碼應該與每個部分的解釋一起作業:
struct ContentView: View {
//Your variable. @State makes it reload the view when changed.
@State var listIsShowing = false
var body: some View {
VStack {
//Your Button
Button (action:{
//Sets variable to true, showing list
listIsShowing = true
},label:{
Text("Search")
})
//To put the button at the top
Spacer(minLength: 0)
//if variable that the button changes = true, show list
if listIsShowing {
//Your list
List {
Text("Your")
Text("list")
Text("appears")
Text("When")
Text("you")
Text("click")
Text("the")
Text("button")
}
//Use below code if you want background to match the top section
//.listStyle(.plain)
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/451157.html
上一篇:AndroidDataBinding新按鈕setOnClickListener
下一篇:角度排序和拆分和陣列
