【问题标题】:SwiftUI picker Extra arguments at positions #1, #2, #3 in callSwiftUI 选择器 调用中位置 #1、#2、#3 的额外参数
【发布时间】:2021-01-29 16:48:41
【问题描述】:

我正在尝试使用 swiftUI 制作分段选择器。 Xcode一直告诉我代码中有错误,特别是以下2个错误:

  1. 调用中#1、#2、#3 位置的额外参数
  2. “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
        
    }
}

Code Errors

【问题讨论】:

  • 在您的项目(不是 SwiftUI 的一部分)中是否有您创建的另一个名为 Picker 的结构或类?
  • 不。我刚刚检查以确保没有任何其他结构或类被称为 Picker。

标签: swift swiftui


【解决方案1】:

这是固定的变体。使用 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())
        
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-07-25
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-08
    相关资源
    最近更新 更多