English 中文(简体)
快速发展数据库
原标题:SwiftData ForEach pull value from loop and use value in a .sheet view

我来自平线和网络发展,因此对迅速和快速发展来说仍然很新,我希望这样做的是通过数据模型,并通过某些数据进行表率。 你能够分享帮助我理解的任何信息都是有益的。 即便是我正确方向的一点也更好了。 这是我与以下方面合作:

 @Environment(.modelContext) private var modelContext
 @Query private var accounts: [LedgerAccounts]
 @State var sheetEditAccount: Bool = false
ForEach(accounts) { account in
                        
                        let accountNumberString = account.numberOfAccount
                        let accountNumberStringValue = String(accountNumberString.suffix(4))
                        
                        HStack {
                            VStack {
                                Text("#" + accountNumberStringValue)
                                    .font(.footnote)
                                    .fontWeight(.thin)
                                    .padding(.trailing, 20)
                            }
                            VStack {
                                Text("(account.nameOfAccount)")
                                    .font(.subheadline)
                                    .fontWeight(.semibold)
                            }
                            VStack {
                                Text(account.amountOfAccount, format: .currency(code: Locale.current.currency?.identifier ?? "USD"))
                                    .font(.subheadline)
                                    .fontWeight(.semibold)
                                    .frame(maxWidth: .infinity, alignment: .trailing)
                            }
                        }
                        .swipeActions(edge: .leading, allowsFullSwipe: false, content: {
                            // Edit Account
                            Button(action: {
                                sheetEditAccount.toggle()
                            }, label: {
                                Image(systemName: "gearshape.arrow.triangle.2.circlepath")
                            })
                            .tint(Color.blue)
                            
                            Divider()
                            
                            // View Account
                            Button {

                                    } label: {
                                        Image(systemName: "eye.circle")
                                    }
                                    .tint(Color.gray)
                        })
                        .sheet(isPresented: $sheetEditAccount) {
                            print("Sheet Dismissed")
                        } content: {
                            EditAccountView()
                                .presentationDetents([.medium])
                                
                        }

I have searched google and stackoverflow not sure if I am asking the right question. Cause I have yet to find something that makes since to me.

问题回答

您可使用<代码>.sheet(项目:......)(如@lorem ipsum所述),例如:

struct ContentView: View {
    //....
    
    @State var selectedAccount: LedgerAccounts? //<--- here
    
    var body: some View {
        ForEach(accounts) { account in
            //....
            .swipeActions(edge: .leading, allowsFullSwipe: false, content: {
                // Edit Account
                Button(action: {
                    selectedAccount = account //<--- here
                }, label: {
                    Image(systemName: "gearshape.arrow.triangle.2.circlepath")
                })
                //....
           } // end of ForEach
            
            .sheet(item: $selectedAccount) { account in //<--- here
                EditAccountView(account: account)
                    .presentationDetents([.medium])
            }
            // ...




相关问题
SwiftUI: How do I position a button x points above a sheet?

I am trying to recreate a Maps-style UI with a persistent bottom sheet and controls fixed above. Apple Maps UI with controls above ☝️ Example here, the "Look Around" binoculars button and ...

BraintreeDropIn deprecated functions error

I m getting this error on the latest release of BraintreeDropIn, I really don t get it since based on the patch notes, this should ve been addressed already, I have already tried cleaning derived data,...

how to limit zoom level in map swift ui?

how to limit zoom level in map swift ui i have map and need to make zoom level limited Map(coordinateRegion: $region,annotationItems: viewModel.nearbyGyms) { item in ...

UIImageView - How to get the file name of the image assigned?

Is it possible to read the name of an UIImageView s UIImage that s presently stored in the UIImageView? I was hoping you could do something kind of like this, but haven t figured it out. NSString *...

热门标签