错误:类型“ UIButton.ButtonType”没有成员“提交”

时间:2019-11-18 20:38:00

标签: ios swift swift3 uibutton

有人要求我尝试为iOS应用程序获取旧的存储库以进行编译,并从以下代码中获取此错误:

//SubmitButton.swift
@objc enum ButtonType: Int {
    case submit
    case response
    case accept
    case decline
    case label
    case survey
    case create
}

class SubmitButton: UIButton {
    private let source: [ButtonType: [String]] = [.submit: ["Submit consult", "Submitting", "consult submitted"],
                                                  .accept: ["Accept consult", "Accepting", "consult accepted"],
                                                  .decline: ["Decline consult", "Declining", "consult declined"],
                                                  .response: ["Reply"],
                                                  .survey: ["Report Outcome", "Submitting", "Outcome reported"],
                                                  .create: ["New consult", "Creating New consult", "New consult"]]
    public var type: ButtonType

...
...
...
}

使用Xcode 10.0,应用是用Swift 3编写的。

不幸的是,我不了解Swift,这是我第一次接触iOS应用。想通了,我想在这里问...

1 个答案:

答案 0 :(得分:3)

ButtonType中使用SubmitButton时,代码引用的是预定义的UIButton.ButtonType,这不是我们在上面代码中看到的枚举。

请将ButtonType enum重命名为其他名称,它应该可以工作:

//SubmitButton.swift
@objc enum CustomButtonType: Int {
    case submit
    case response
    case accept
    case decline
    case label
    case survey
    case create
}

class SubmitButton: UIButton {
    private let source: [CustomButtonType: [String]] = [.submit: ["Submit consult", "Submitting", "consult submitted"],
                                                  .accept: ["Accept consult", "Accepting", "consult accepted"],
                                                  .decline: ["Decline consult", "Declining", "consult declined"],
                                                  .response: ["Reply"],
                                                  .survey: ["Report Outcome", "Submitting", "Outcome reported"],
                                                  .create: ["New consult", "Creating New consult", "New consult"]]
    public var type: CustomButtonType
}