【问题标题】:Value of type 'UIButton' has no member 'enumerate'“UIButton”类型的值没有成员“枚举”
【发布时间】:2020-08-16 06:36:44
【问题描述】:
func addButtonConstraints(buttons:UIButton, mainView:UIView) {
    for(index, buttons) in buttons.enumerate{

但是 xcode 给我这个错误 --->'UIButton' 类型的值没有成员 'enumerate'

【问题讨论】:

    标签: swift xcode uibutton


    【解决方案1】:

    enumerate 属性是Array 的成员。所以这里只有一个UIButton,不能枚举,除非是[UIButton]。

    替换:

    func addButtonConstraints(buttons:UIButton, mainView:UIView) {
        for(index, buttons) in buttons.enumerate{
    

    与:

    func addButtonConstraints(buttons: [UIButton], mainView: UIView) {  
        for (index, button) in buttons.enumerated() {
    

    【讨论】:

    • 它不起作用,当我更换它时发生了同样的错误(完全一样)。我现在正在研究它,当我指出它时会订阅解决方案。
    • 这不太可能。枚举部分应该已经工作了。该解决方案已经过测试并且可以正常工作。你可能犯了其他错误。
    • 嗨,亲爱的弗兰克:我想我只是说出来但不是你的回答,我怀疑我们使用的是 Swift 版本。
    • 我的解决方案如下:
    • func addButtonConstraints(buttons: [UIButton], mainView: UIView) { for(index, button) in buttons.enumerated() {
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2017-05-03
    • 2023-03-05
    相关资源
    最近更新 更多