首页 > 解决方案 > 按下按钮时, button.setImage(nil) 不起作用

问题描述

我正在尝试创建日语填字游戏。将按钮用作单元格。尝试插入系统映像时,它可以工作(案例模式 1)。但是当我选择其他模式(2)时,图标不会消失。

let img1 = UIImage(systemName: "multiply"))

@IBAction func cellClicked(_ sender: UIButton) {
    for cell in cellButtons {
        if cell.tag == sender.tag {
            switch typeCell { //when mode changes
                    case 1:
                        cell.setImage(img1, for: .normal)  //work
                    default/*2*/:
                        cell.setImage(nil, for: .normal) //don't work, but running without errors
                    }
        }
    } 
}

我试图只使用发件人(没有if cell.tag == sender.tag; 没有工作),然后创建 IBOutlet 集合并运行上面的代码。

更新:我发现并决定使用 .isHidden。那行得通,我也解决了我的其他问题:) 谢谢!

标签: iosswiftxcodeuibutton

解决方案


推荐阅读