gpt4 book ai didi

ios - [UIButton copyWithZone :]: unrecognized selector sent to instance

转载 作者:行者123 更新时间:2023-11-28 15:15:38 30 4
gpt4 key购买 nike

    func createRowOfButtons(buttonTitles: [NSString]) -> UIView {
var buttons = [UIButton]()
let keyboardRowView = UIView(frame: CGRect(x: 0, y: 0, width: 320, height: 50))
var dict = [UIButton:String]()
for buttonTitle in buttonTitles
{
let button = createButtonWithTitle(title: buttonTitle as String)
buttons.append(button)
keyboardRowView.addSubview(button)
dict.updateValue("\(buttonTitle)", forKey: button)
}
allButtons = NSMutableDictionary(dictionary: dict)
//error:[UIButton copyWithZone:]: unrecognized selector sent to instance 0x7e011bc0
addIndividualButtonConstraints(buttons: buttons, mainView:keyboardRowView)
return keyboardRowView
}

我是 iOS 的新手,我想创建一个 UIButtonNSMutableDictionary 但它给出了以下错误:

Cannot cast 'UIButton' to 'NSCopying'.

我不明白为什么会出现这个错误。

提前致谢。

最佳答案

UIButton 不符合 NSCopying protocol 因此您不能将其用作 NSDictionary 中的键

来自 Apple 文档:

The key is copied (using copyWithZone:; keys must conform to the NSCopying protocol).

引用:This Question 的 pheelicks 回答

关于ios - [UIButton copyWithZone :]: unrecognized selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46908041/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com