swift - 调用 SwiftUI 中位置 #11、#12 的额外参数
问题描述
我在 SwiftUI 中的切换开关上不断收到“位置 #11、#12 的额外参数”错误。我见过其他人有“Extra Arguments in call”错误,但答案似乎没有帮助;另外,我的错误是“位置#11、12”,我没有看到其他人发生这种情况。如果有区别,我正在使用 Xcode 12 beta。
import SwiftUI
let defaults = UserDefaults.standard
let notifsEnabled = defaults.bool(forKey: "NotifsEnabled")
struct Settings: View {
@State var class11: String = defaults.string(forKey: "class11") ?? ""
@State var class12: String = defaults.string(forKey: "class12") ?? ""
@State var class13: String = defaults.string(forKey: "class13") ?? ""
@State var class14: String = defaults.string(forKey: "class14") ?? ""
@State var class21: String = defaults.string(forKey: "class21") ?? ""
@State var class22: String = defaults.string(forKey: "class22") ?? ""
@State var class23: String = defaults.string(forKey: "class23") ?? ""
@State var class24: String = defaults.string(forKey: "class24") ?? ""
@State var scheduleNotifications = notifsEnabled
var body: some View {
VStack(alignment: .leading) {
Toggle(isOn: $scheduleNotifications) { //Extra arguments at positions #11, #12 in call
Text("Daily schedule notifications")
}
if scheduleNotifications {
Text(CreateNotifs())
} else {
Text(DeleteNotifs())
}
Text("This App will send you a reminder each day at 8:25 with the schedule for that day")
.font(.caption)
.foregroundColor(Color.gray)
Divider()
TextField("Class 1-1", text: $class11)
TextField("Class 1-2", text: $class12)
TextField("Class 1-3", text: $class13)
TextField("Class 1-4", text: $class14)
TextField("Class 2-1", text: $class21)
TextField("Class 2-2", text: $class22)
TextField("Class 2-3", text: $class23)
TextField("Class 2-4", text: $class24)
//Spacer()
}
.padding()
.navigationBarTitle("Settings")
}
}
解决方案
ViewBuilder 在一个容器中仅支持不超过 10 个静态视图...这是您出错的原因
只是将它们分组
Group {
TextField("Class 1-1", text: $class11)
TextField("Class 1-2", text: $class12)
TextField("Class 1-3", text: $class13)
TextField("Class 1-4", text: $class14)
TextField("Class 2-1", text: $class21)
TextField("Class 2-2", text: $class22)
TextField("Class 2-3", text: $class23)
TextField("Class 2-4", text: $class24)
}
推荐阅读
- java - Java如何良好实践:实用程序类中的映射
- android - 如何以编程方式安装下载的 APK 文件?
- javascript - 拉取随机数组成员并存储该成员的索引
- ios - 迅速从火力库中获取不正确的值
- javascript - 有没有办法等到每个 html 组件都处于其位置向用户显示网站?
- python - 如何解释和控制 XGBRegressor 树模型选择的参数
- amazon-web-services - Amazon Athena:查询以找出连续 10 天合规性 = 0 的患者
- node.js - (节点:52213)警告:在循环依赖中访问模块导出的不存在属性“MongoError”(使用节点--trace-warnings
- amazon-s3 - 我必须使用哪种文件格式支持追加?
- ethereum - 如何使用 UniswapV2Router02 合约用 swapExactTokensForETH() 将 Token 换成 ETH