我想進行編輯并添加一個按鈕,如下圖所示的圓圈按鈕。我需要這些按鈕,以便我可以更改檔案夾的屬性。單擊默認的 SwiftUI 編輯按鈕時,如何使此按鈕作業?
我想要的是:
(在單擊編輯按鈕之前)
![如何為串列中的一行/每個回圈獲取“編輯”按鈕?[SwiftUI]](https://img.uj5u.com/2022/02/17/60561b158eac464caa90bda53b3e488c.png)
(點擊編輯按鈕后)
![如何為串列中的一行/每個回圈獲取“編輯”按鈕?[SwiftUI]](https://img.uj5u.com/2022/02/17/16216d1720d7417fb7c69182ac325e18.jpg)
我目前擁有的:
(在單擊編輯按鈕之前)
![如何為串列中的一行/每個回圈獲取“編輯”按鈕?[SwiftUI]](https://img.uj5u.com/2022/02/17/c196f0d9f65b4422b29725a5ad904767.png)
(點擊編輯按鈕后)
我的代碼:
var body: some View {
ZStack {
List {
ForEach(searchResults, id: \.self.id) { dir in
Section(dir.title) {
ForEach(dir.getChildFolders(), id: \.self.id) { folder in
NavigationLink(destination: DirectoryView(directory: folder)) {
Label(folder.title, systemImage: "folder")
}
}
.onDelete(perform: { offsets in
dir.items.remove(atOffsets: offsets)
updateView.update()
})
.onMove(perform: { source, destination in
dir.items.move(fromOffsets: source, toOffset: destination)
updateView.update()
})
}
}
}
uj5u.com熱心網友回復:
您需要自己顯示按鈕。
首先,確保您有一些@Statevar 跟蹤是否切換了編輯模式:
@State var editing: Bool = false
然后,在您的 中,在if you arebody旁邊顯示圓形按鈕:NavigationLinkediting
var body: some View {
ZStack {
List {
ForEach(searchResults, id: \.self.id) { dir in
Section(dir.title) {
ForEach(dir.getChildFolders(), id: \.self.id) { folder in
HStack {
NavigationLink(destination: DirectoryView(directory: folder)) {
Label(folder.title, systemImage: "folder")
}
if editing {
Spacer()
Button(action: {
// Perform circle button action here
}) {
Image(systemName: "ellipsis.circle")
}
}
}
}
.onDelete(perform: { offsets in
dir.items.remove(atOffsets: offsets)
updateView.update()
})
.onMove(perform: { source, destination in
dir.items.move(fromOffsets: source, toOffset: destination)
updateView.update()
})
}
}
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/425253.html
下一篇:如何在反應中添加多個條件?
