Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 导航到上一个控制器SwiftUI_Ios_Swift_Swiftui - Fatal编程技术网

Ios 导航到上一个控制器SwiftUI

Ios 导航到上一个控制器SwiftUI,ios,swift,swiftui,Ios,Swift,Swiftui,我目前处于特定瓶子详细视图的视图控制器中,并为用户提供一个操作表,使他们能够删除产品。因为他们可以删除此产品,所以一旦成功删除,我需要导航到上一个控制器。我怎样才能在斯威夫特做到这一点?这将在API请求成功的情况下完成 struct WishlistView: View { @State private var showingSheet = false @State private var show_modal: Bool = false let wishlist: Wi

我目前处于特定瓶子详细视图的视图控制器中,并为用户提供一个操作表,使他们能够删除产品。因为他们可以删除此产品,所以一旦成功删除,我需要导航到上一个控制器。我怎样才能在斯威夫特做到这一点?这将在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")
            }
        }
    }
}

是否要转到上一个导航视图? 如果是,请尝试以下操作:

1。首先,添加一个环境变量。

@Environment(\.presentationMode) var presentationMode
self.presentationMode.wrappedValue.dismiss()
2。将以下代码放在您希望解雇的位置。

@Environment(\.presentationMode) var presentationMode
self.presentationMode.wrappedValue.dismiss()
例如:

struct WishlistView: View {
    @Environment(\.presentationMode) var presentationMode
    @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")
                self.presentationMode.wrappedValue.dismiss()
        case let .failure(_):
                print("error")
            }
        }
    }
}

您正在查找
\.presentationMode
上的
discouse()