Re: new to cocoa
Re: new to cocoa
- Subject: Re: new to cocoa
- From: Alejandro Marcos Aragón <email@hidden>
- Date: Fri, 14 May 2010 00:18:51 -0500
Thanks Kiel for answering so fast. I realized that this was the case a couple of days ago. It took some time for my message to appear in the mailing list. I was trying to associate buttons with objects so that when I press the button I can do certain action on the corresponding object. I solved the problem using just two regular NSMutableArrays. It's doing the same thing though, creating a map of buttons to objects, but using the index to these arrays. It doesn't seem to be very efficient though.
aa
On May 13, 2010, at 11:38 PM, Kiel Gillard wrote:
> On 12/05/2010, at 6:36 AM, Alejandro Marcos Aragón wrote:
>
>> Hi all,
>>
>> I'm new to Cocoa, and I couldn't find information about an error that I'm getting on the web. I'm trying to create an NSMutableDictionary where the keys are of type UIButton*:
>>
>>
>> // create button for unit
>> UIButton* unitButton = [[UIButton alloc] init];
>> [sourceButtonMap setObject:[NSString stringWithString:@"no"] 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?
>
> Welcome to iPhone OS development!
>
> This most certainly is happening because you cannot use UIButton objects as keys in a dictionary because NSDictionary copies the objects used as keys. Furthermore, UIButton does implement the NSCopying methods.
>
>> Can anyone point me why I'm getting this error? Thank you all,
>
> <http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSDictionary_Class/Reference/Reference.html>
>
> See the second paragraph of the section titled "Overview".
>
> I suggest you revise your design. I don't know exactly what you're trying to do. Perhaps @"no" should be the key for the UIButton?
>
> Kiel
>
>
>>
>> aa_______________________________________________
>>
>> Cocoa-dev mailing list (email@hidden)
>>
>> Please do not post admin requests or moderator comments to the list.
>> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>>
>> Help/Unsubscribe/Update your Subscription:
>>
>> This email sent to email@hidden
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden