首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >SwiftUI,navigationBarItems在程序取消模态后不工作

SwiftUI,navigationBarItems在程序取消模态后不工作
EN

Stack Overflow用户
提问于 2020-06-28 14:25:04
回答 1查看 139关注 0票数 0

使用SwiftUI,

我展示了一个模式,然后以编程方式拒绝它。问题是,第二次,navigationBarItems没有反应,我不能再强迫他们了。

如果我用滑动手势拒绝模态,那么它可以正常工作,但当我调用self.presentationMode.wrappedValue.dismiss()时就不行了。

HomeView.swift

代码语言:javascript
复制
struct HomeView: View {
    @Environment(\.managedObjectContext) var moc;
    
    @State private var isSureToResetCounter = false;
    var body: some View {

        func handleLeadingBtnPress() -> Void {
            self.isSModalPresented = true;
        }
                
        return
            NavigationView {
                VStack(alignment: .center, spacing: 20.0) {
                    Spacer(minLength: 10)
                  // ...
                }
                .padding(20)
                .background(Color.secondary)
                .edgesIgnoringSafeArea(.all)
                .navigationBarTitle(Text(""), displayMode: .inline)
                    
                .navigationBarItems(
                    leading:
                    Button(action: handleLeadingBtnPress) {
                        Text("Save")
                            .foregroundColor(.textPrimary)
                    }.sheet(isPresented: self.$isSModalPresented) {
                        SaveModalView()
                            .environment(\.managedObjectContext, self.moc)
                            .modifier(SystemServices())
                    }, trailing:
                    NavigationLink(destination: ActivityListView()) {
                        Text("History")
                            .foregroundColor(.textPrimary)
                })
                    .gesture(tap)
        }
    }
}

SaveModalView.swift

代码语言:javascript
复制
struct SaveModalView: View {
    @Environment(\.presentationMode) private var presentationMode
    @Environment(\.managedObjectContext) var moc;
    //...
    func handleSaveActivity() -> Void {        
        let newActivity = Activity(context: self.moc);
        do {
            try moc.save();
        } catch {
            print("coulnd save activity")
        }
        AppStoreReviewManager.requestReviewIfAppropriate();
        self.presentationMode.wrappedValue.dismiss()
    }
//...

我做错了什么?

编辑:这个bug似乎只发生在模拟器上。

EN

回答 1

Stack Overflow用户

发布于 2020-06-29 12:40:20

这是SwiftUI在某些Xcode版本上的一个已知错误。我建议您尝试Xcode的最新版本,看看是否可行。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62623849

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档