【发布时间】:2021-07-01 00:06:24
【问题描述】:
我目前处于特定瓶子详细视图的视图控制器中,并为用户提供了一个操作表,使他们能够删除产品。由于他们可以删除此产品,因此一旦成功删除,我需要导航到以前的控制器。我怎样才能在 Swift 中做到这一点?这将在 API 请求成功时完成。
struct WishlistView: View {
@State private var showingSheet = false
@State private var show_modal: Bool = false
let wishlist: Wishlist
var body: some View {
Text("Hello, Marketplace!")
.navigationBarTitle(wishlist.name)
.navigationBarItems(trailing:
HStack {
Button(action: {
showingSheet = true
}) {
Image(systemName: "ellipsis.circle.fill")
}
.actionSheet(isPresented: $showingSheet) {
ActionSheet(title: Text("Change background"), message: Text("Select a new color"), buttons: [
.default(Text("Delete Wishlist"), action: {
destroyWishlist()
}),
.default(Text("Green")),
.default(Text("Blue")),
.cancel()
])
}
.foregroundColor(Color("Rye"))
}
)
.listStyle(InsetGroupedListStyle())
}
func destroyWishlist() {
AF.request("http://localhost:3000/wishlist/\(wishlist.id)", method: .delete).responseJSON { response in
switch response.result {
case .success:
print("successful")
case let .failure(_):
print("error")
}
}
}
}
【问题讨论】:
-
您在
\.presentationMode上寻找dismiss()吗? stackoverflow.com/questions/56513568/…