首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >SwiftUI导航链接或表示链接不工作

SwiftUI导航链接或表示链接不工作
EN

Stack Overflow用户
提问于 2019-07-03 20:55:29
回答 3查看 4.1K关注 0票数 5

在使用NavigationLink或swiftUI中的表示链接时,导航控制器不会推送或显示新视图,从而导致错误

"WindowServer display_timer_callback:意外状态“

代码语言:javascript
运行
复制
ForEach(self.items.identified(by: \.name)) {  item in


    NavigationLink(destination: Text("DT In the House")) {
        CategoryItem(item: item)


    }
}

[] nw_connection_receive_internal_block_invoke C4接收应答失败,错误“操作取消”

EN

回答 3

Stack Overflow用户

发布于 2019-07-05 17:54:19

我认为这是当前PresentationLink测试版中的SwiftUI错误。当我试图重新打开模式时,我也会遇到同样的错误。

EDIT1: NavigationLink需要嵌入到NavigationView中,如果没有,将显示消息[WindowServer] display_timer_callback: unexpected state (now:1abc3d3ccc7 < expected:1abc3d91a0f)

EDIT2: PresentationLink只在嵌入NavigationBarItems或List之类的东西时才会出现问题。

票数 3
EN

Stack Overflow用户

发布于 2019-07-07 09:58:52

好像是个虫子。我设法想出了一个(肮脏的)解决办法:

代码语言:javascript
运行
复制
private enum SetPresentedViewKey: EnvironmentKey {
    static var defaultValue: (AnyView?) -> () {
        fatalError()
    }
}

private extension EnvironmentValues {
    var setPresentedView: (AnyView?) -> () {
        get {
            self[SetPresentedViewKey.self]
        } set {
            self[SetPresentedViewKey.self] = newValue
        }
    }
}

/// A replacement for the buggy (as of Xcode 11 b3) `PresentationLink`.
public struct PresentationLink2<Destination: View, Label: View>: View {
    public let destination: Destination
    public let label: Label

    @Environment(\.setPresentedView) private var setPresentedView
    @State private var presentedView: AnyView? = nil

    public init(destination: Destination, @ViewBuilder _ label: () -> Label) {
        self.destination = destination
        self.label = label()
    }

    private struct _Body<Destination: View, Label: View>: View {
        @Environment(\.setPresentedView) private var setPresentedView

        let destination: Destination
        let label: Label

        init(destination: Destination, label: Label) {
            self.destination = destination
            self.label = label
        }

        var body: some View {
            Button(action: present, label: { label })
        }

        func present() {
            setPresentedView(AnyView(destination))
        }
    }

    public var body: some View {
        _Body(destination: destination, label: label)
            .environment(\.setPresentedView, { self.presentedView = $0 })
            .presentation(presentedView.map {
                Modal($0, onDismiss: { self.presentedView = nil })
            })
    }
}

只需将上面的代码复制到您的代码库中,使用PresentationLink2而不是PresentationLink

正如@kozlowsqi所指出的,当嵌入到一个PresentationLink中时,NavigationView似乎被破坏了。令人震惊的是,它在Xcode beta 3中仍然是坏的。

编辑:我已经通过一个新的反馈助理应用程序,FB6525020雷达。请提出你自己和参考我的,并希望这将解决贝塔4。

票数 3
EN

Stack Overflow用户

发布于 2019-07-09 19:38:39

我已经创建了一个更可靠的PresentationLink替代品。希望一旦beta 4发布,它就不再需要了。

你可以在这里找到一个要点:https://gist.github.com/petercv/3fba967a69b262901053fc8638b7851b

我还添加了对.isModalInPresentation(_ value: Bool)修饰符的支持,以设置UIViewController的isModalInPresentation属性。希望苹果会很快加入这一行列。

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

https://stackoverflow.com/questions/56877805

复制
相关文章

相似问题

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