Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

XcodeNewb

macrumors member
Original poster
Feb 6, 2009
79
0
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:

Code:
[[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
 
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:

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

[[myDateArray objectAtIndex:i] setHidden:YES];
 
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!
 
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).

Code:
((UIButton* )[[myDateArray objectAtIndex:i]).hidden = YES;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.