PDA

View Full Version : NSMutableArray of UIButton objects




XcodeNewb
Jul 29, 2009, 10:12 PM
I have an NSMutableArray that I have filled with UIButton objects. The problem I am having is that on a certain user action I want to hide all of the buttons that I have added to that array.

I tried something like:


[[myDateArray objectAtIndex:i] setHidden];


but this did not work. It is like I lose that fact that the objects in the array are of UIButton type.

Any ideas how I can retrieve the type of the object to use it's properties?

Thanks



PhoneyDeveloper
Jul 29, 2009, 10:27 PM
It's true that when you get an object back from an array it has a type of id but you can certainly send it messages. These should work, for instance:

UIButton* b = [myDateArray objectAtIndex:i];
b.hidden = YES;

[[myDateArray objectAtIndex:i] setHidden:YES];

XcodeNewb
Jul 29, 2009, 10:30 PM
Thanks Phoney. I swear I tried both of those and they didn't work. Works fine now though. The little things we waste our time on are amazing!

moral-hazard
Jul 29, 2009, 11:20 PM
I have an NSMutableArray that I have filled with UIButton objects. The problem I am having is that on a certain user action I want to hide all of the buttons that I have added to that array.

but this did not work. It is like I lose that fact that the objects in the array are of UIButton type.

Any ideas how I can retrieve the type of the object to use it's properties?

Thanks

Obj-C does not know that all of the objects in the array are UIButtons - cast it. Phoney's code does the same thing. You basically have to "force" obj-C to treat it as a UIButton, which works out fine (assuming that it is).


((UIButton* )[[myDateArray objectAtIndex:i]).hidden = YES;