SWIFT: 按钮不会在点击时消失

SWIFT: Button is not disappearing on click

当我的 UITableViewCell 中的 UIButton 被点击时,我希望它消失。我尝试了其他 Stack Overflow 帖子的一些建议,但我得到了同样的错误:"fatal error: unexpectedly found nil while unwrapping an Optional value".

下面是视图控制器和我的代码的截图:

确保您的按钮 voteButtonLabel 链接到情节提要出口,在这种情况下通常会抛出错误。

我认为您只是不想让用户再次投票,所以您可以将其隐藏。或者你想通过完全删除它来实现一些特别的东西吗? 尝试:

voteBuoonLabel.hidden = true

voteButtonLabel 不需要 var,可以将其删除。 只需要将错误行替换为 sender.hidden = true

将函数更改为voteButton(sender:UIButton)