swift - SwiftUI 选择器 调用中位置 #1、#2、#3 的额外参数
问题描述
我正在尝试使用 swiftUI 制作分段选择器。Xcode一直告诉我代码中有错误,特别是以下2个错误:
- 调用中位置#1、#2、#3 的额外参数
- “Picker”类型的值没有成员“pickerStyle”
我在一个新的干净项目中运行了这段代码,它编译没有问题,我得到了分段选择器的预期结果。
其他 swiftUI 代码可以正常工作并正确编译。此外,部署目标是 iOS 13.0。
我不确定为什么会发生此错误。
编辑 -没有其他称为 Picker 的结构或类。
编辑 -运行 Xcode 12.3。
import SwiftUI
struct PickerView: View {
@State private var selectedView = 0
var body: some View {
Picker(selection: selectedView, label: Text("What is your favorite color?")) { //error 1 is on this line
Text("Red").tag(0)
Text("Green").tag(1)
Text("Blue").tag(2)
}.pickerStyle(SegmentedPickerStyle()) //error 2 is on this line
}
}
解决方案
这是固定的变体。使用 Xcode 12.4 测试。
struct PickerView: View {
@State private var selectedView = 0
var body: some View {
Picker(selection: $selectedView, label: Text("What is your favorite color?")) { //error 1 is on this line
Text("Red").tag(0)
Text("Green").tag(1)
Text("Blue").tag(2)
}.pickerStyle(SegmentedPickerStyle())
}
}
推荐阅读
- java - 每当我在服务器上运行我的 java sevlet 代码时抛出 404 错误
- python - 解析 txt 的特定区域,与字符串列表进行比较,然后生成由匹配项组成的新列表
- java - 带有@WebMvcTest 的测试切片正在加载大量与目标无关的控制器
- java - Jenkins 无法为我的 Selenium 项目编译 Maven
- vuex - 访问 quasar 中的 store vuex for meta
- laravel - Laravel group by、count 和 access 和 eloquent 的关系
- c# - C# MVVM ASP.net API 隐式转换错误
- websocket - 现在还需要 websocket 回退吗?
- nginx - nginx 未检测到 CSS 和 JS - 服务器响应状态为 404
- django - 如何在 django 模板中使上下文变量动态化