SwiftUI:随机的“通话中的其他参数"错误

编程入门 行业动态 更新时间:2024-10-08 13:31:01
本文介绍了SwiftUI:随机的“通话中的其他参数"错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我正在尝试学习SwiftUI和Combine.我通常通过制作一个简单的小费计算器来开始新技术.

So I'm trying to learn SwiftUI and Combine. I usually start new tech by making a simple tip calculator.

我似乎得到了一个随机的通话中的额外参数".编码时出错这是我的SwiftUI文件

I seem to be getting a random "Extra argument in call." error while coding Here is my SwiftUI File

import SwiftUI internal enum ReceiptRowType { case subtotal case tax case total case tip case grandTotal } struct TipView: View { @ObservedObject internal var adBannerView: BannerAdView = BannerAdView() @ObservedObject internal var receiptViewModel: ReceiptViewModel private let percentageFormatter: NumberFormatter = { let f = NumberFormatter() f.numberStyle = .percent return f }() var body: some View { ZStack { Color.white .scaledToFit() VStack { if adBannerView.adHasLoaded { adBannerView .frame(maxHeight: adBannerView.adHeight) .animation(.easeInOut(duration: 2.0)) } BorderView() Text(ARCHLocalizedStrings.receipt) .foregroundColor(Color.gray) BorderView() HStack { Spacer() Button(action: { self.receiptViewModel.addNewReceiptItem() }) { Text(ARCHLocalizedStrings.buttonTitleAddItem) } } BorderView() ScrollView { ForEach(receiptViewModel.receiptItems) { receiptItem in ItemView(receiptItem: receiptItem) if receiptItem != self.receiptViewModel.receiptItems.last { Divider() } } } BorderView() BottomOfReceiptRow(receiptViewModel: receiptViewModel, type: ReceiptRowType.subtotal, title: ARCHLocalizedStrings.subtotal) BottomOfReceiptRow(receiptViewModel: receiptViewModel, type: ReceiptRowType.tax, title: ARCHLocalizedStrings.tax) } .padding(.horizontal, ARCHSwiftUILayoutConstants.defaultPaddingAndSpacing) } } } struct BorderView: View { var body: some View { Text("================================") .lineLimit(1) .foregroundColor(Color.gray) .minimumScaleFactor(0.5) } } struct ItemView: View { @ObservedObject var receiptItem: ReceiptItemViewModel var body: some View { HStack { TextField(receiptItem.name, text: $receiptItem.name) .textFieldStyle(RoundedBorderTextFieldStyle()) .foregroundColor(Color.gray) .multilineTextAlignment(TextAlignment.leading) TextField("Price", value: $receiptItem.price, formatter: ARCHUtilities.currencyFormatter) .textFieldStyle(RoundedBorderTextFieldStyle()) .foregroundColor(Color.gray) .multilineTextAlignment(TextAlignment.trailing) .minimumScaleFactor(0.5) .frame(width: ARCHSwiftUILayoutConstants.widthForCurrency) } } } struct BottomOfReceiptRow: View { @ObservedObject internal var receiptViewModel: ReceiptViewModel internal var type: ReceiptRowType internal var title: String var body: some View { HStack { Spacer() Text(title) .foregroundColor(Color.gray) if type == ReceiptRowType.subtotal { Text("\(receiptViewModel.subtotal)") .foregroundColor(Color.gray) .frame(width: ARCHSwiftUILayoutConstants.widthForCurrency) } else if type == ReceiptRowType.tax { Text("\(receiptViewModel.taxRate)") .foregroundColor(Color.gray) .frame(width: ARCHSwiftUILayoutConstants.widthForCurrency) } else if type == ReceiptRowType.total { Text("\(receiptViewModel.total)") .foregroundColor(Color.gray) .frame(width: ARCHSwiftUILayoutConstants.widthForCurrency) } else if type == ReceiptRowType.tip { } else if type == ReceiptRowType.grandTotal { Text("\(receiptViewModel.grandTotal)") .foregroundColor(Color.gray) .frame(width: ARCHSwiftUILayoutConstants.widthForCurrency) } } } } struct TipView_Previews: PreviewProvider { static var previews: some View { TipView(receiptViewModel: ReceiptViewModel()) } }

但是,如果我在TipView主体上添加另一个视图(任何视图),我似乎会收到调用中的额外参数"错误.

However, if I add another view on the TipView body (Any View) I seem to get a "Extra argument in call" error.

此处的错误图片

有人知道发生了什么吗?

Does anyone know what's going on?

推荐答案

尝试围绕您的视图创建一个组{}.Swiftui只允许10个...与组一起可以添加更多.或使用子视图...(也将是更简洁的代码)

try making a Group { } around your views. just 10 are allowed in Swiftui...with group you can add more. or use subviews...(would be cleaner code too)

更多推荐

SwiftUI:随机的“通话中的其他参数"错误

本文发布于:2023-11-26 21:54:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635343.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   参数   SwiftUI   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!