繁体   English   中英

如何在 swiftUI 中不作为绑定传递而访问父视图变量

[英]How to access parent view variable without passing as binding in swiftUI

我正在使用showCommentView变量,它是我在子视图中传递的@State变量,因为@Binding这里的问题是我需要作为绑定传递的每个子视图。 我怎样才能独立实现它

struct AudioListView: View {

    @State var showCommentView = false 
   SecondView(showCommentView: $showCommentView)
}

struct SecondView {
    @Binding var showCommentView:Bool
}

我认为您应该将showCommentView变量作为绑定传递,如下所示:

struct AudioListView: View {
   @State var showCommentView = false 
   SecondView(showCommentView: .constant(showCommentView))
}

struct SecondView {
   @Binding var showCommentView:Bool
}

如果你想使用 is @State@Binding你可以随意使用它

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM