首页 > 解决方案 > SwiftUI - 我的列表并没有一直到我的导航视图

问题描述

我似乎找不到我的列表和导航视图之间有空格的原因。当我删除我的导航栏项目时,我的列表会填满空间,当我有我的导航栏项目时,导航栏和我的列表之间会有一个间隙。我用于导航栏的样式是内联的。这是 Xcode 中的错误还是我缺少的东西。这是下面的代码。

...

import SwiftUI

struct DigitalReceiptContent: View {
    @ObservedObject var store = ReceiptStore()
    @State var showProfile = false
    
    func addUpdate() {
        store.updates.append(Update(name: "New Purchase", purchase: "$0.00", date: "00/00/21"))
    }
    
    var body: some View {
        
    NavigationView {
    
            List {
                ForEach(store.updates) { update in
                    NavigationLink(destination: FullDigitalReceipt(update: update))
                    {
                     
                        HStack {
                            Circle()
                                .frame(width: 50, height: 50)
                                .background(Color(#colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)))
                                .foregroundColor(.gray)
                                .cornerRadius(50)
                                .shadow(color: Color.black.opacity(0.6), radius: 2, x: 0, y: 1)
                            
                            Text(update.name)
                                .font(.system(size: 20, weight: .bold))
                                .padding(.leading)
                            
                            Spacer()
                            
                            VStack(alignment: .trailing, spacing: 4.0) {
                                Text(update.date)
                                    .font(.caption)
                                
                                Text(update.purchase)
                                    .foregroundColor(Color(#colorLiteral(red: 0.2549019754, green: 0.2745098174, blue: 0.3019607961, alpha: 1)))
                                    .fontWeight(.heavy)
                            }
                        }
                        .padding()
                    }
                }
                .onDelete{ index in
                    self.store.updates.remove(at: index.first!)
                }
                
            }
            .listStyle(GroupedListStyle())
            .navigationBarTitle(Text("Purchases"), displayMode: .inline)
            .navigationBarItems(
                // Selection button; organize purchases
                leading: EditButton(),
                
                trailing: Button(action: {self.showProfile.toggle() }) { Image(systemName: "person.crop.circle")
                }
                .sheet(isPresented: $showProfile) {
                    ProfileSettings()
                })
        }
        
        
    }
}

...

在此处输入图像描述

在此处输入图像描述

标签: swiftlistnavigationview

解决方案


推荐阅读