小编Ale*_* A.的帖子

NSMutableDictionary以UIButton*作为键 - iPhone开发

我是iPhone开发的新手,我有一个问题可能有一个非常简单的答案.我正在尝试向视图添加按钮,这些按钮与我定义的自定义类相关联.当我将按钮添加到视图时,我想知道这些按钮对应的类.这是因为当我按下按钮时,我需要获得有关该类的一些信息,但是消息的接收者是另一个类.我无法找到有关我在网上收到的错误的信息.我遇到的问题是我正在尝试创建一个NSMutableDictionary,其中键的类型为UIButton*,值是我的自定义类型:

   // create button for unit
   UIButton* unitButton = [[UIButton alloc] init];
   [sourceButtonMap setObject:composite forKey:unitButton];
Run Code Online (Sandbox Code Playgroud)

当然,sourceButtonMap是在类中定义的,并在init函数中初始化为 sourceButtonMap = [[NSMutableDictionary alloc] init];

我尝试添加键值对时得到的错误是:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIButton copyWithZone:]: unrecognized selector sent to instance 0x3931e90'

这是因为我不能将UIButton*存储为密钥吗?谁能指出我为什么会收到此错误?谢谢你们,

AA

uibutton nsmutabledictionary

10
推荐指数
2
解决办法
3438
查看次数

标签 统计

nsmutabledictionary ×1

uibutton ×1