当我在 swift ui 中关闭视图时出现错误。我有这个视频。视图像一个外观一样单独打开和关闭。
这是我打开详细视图的代码。
VStack(alignment: .leading) {
Text("Les derniers articles")
.font(.title)
.fontWeight(.bold)
.padding(.leading)
ForEach(observed.articles) {i in
NavigationLink(destination: ArticleDetailScreen(
id_open: i.id,
article_name_open: i.article_name,
article_category_open: i.article_category,
article_description_open: i.article_description,
article_header_URL_image_open: i.article_header_URL_image,
content_open: i.content
)) {
MainArticleElementView(
viewType: "shor",
id: i.id,
article_name: i.article_name,
article_category: i.article_category,
article_description: i.article_description,
article_header_URL_image: i.article_header_URL_image,
content: i.content
)
}.buttonStyle(PlainButtonStyle())
}.frame(minWidth: 0, maxWidth: .infinity, alignment: .center)
}.background(Color(UIColor.systemBackground)).cornerRadius(20)
和我的详细视图的代码:
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
{...}
var body: some View {
ZStack(alignment: .topLeading) {
ScrollView {
VStack(alignment: .leading) {
{...}
Button(action: {
self.presentationMode.wrappedValue.dismiss()
}) {
Image(systemName: "chevron.left.circle.fill")
.resizable()
.scaledToFit()
.frame(width: 30, height: 30)
.foregroundColor(Color(UIColor.secondarySystemBackground))
.background(Color(UIColor.secondaryLabel))
.clipShape(Circle())
.padding().padding(.top, 50)
}
如果你需要任何想法,它会非常棒。太感谢了