NSMutableDictionary with UIButton* as keys - iPhone development
Posted
by Alejandro A.
on Stack Overflow
See other posts from Stack Overflow
or by Alejandro A.
Published on 2010-05-12T15:38:09Z
Indexed on
2010/05/12
15:44 UTC
Read the original article
Hit count: 357
nsmutabledictionary
|uibutton
Hi, I'm new to iPhone development and I have a question that may have a very simple answer. I am trying to add buttons to a view and these buttons are associated with a custom class that I defined. When I add the buttons to the view, I would like to know what class these buttons correspond to. This is because when I press the button, I need to get some information about the class, but the receiver of the message is another class. I couldn't find information about an error that I'm getting on the web. The problem I have is that I'm trying to create an NSMutableDictionary where the keys are of type UIButton* and the values are of my custom type:
// create button for unit
UIButton* unitButton = [[UIButton alloc] init];
[sourceButtonMap setObject:composite forKey:unitButton];
Of course, the sourceButtonMap is defined in the class and initialized in the init function as sourceButtonMap = [[NSMutableDictionary alloc] init];
The error I get when I try to add the key-value pair is:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIButton copyWithZone:]: unrecognized selector sent to instance 0x3931e90'
Is this happening because I can't store UIButton* as keys? Can anyone point me why I'm getting this error? Thank you all,
aa
© Stack Overflow or respective owner