1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

NSMutableArray of UIButton objects

Discussion in 'iPhone/iPad Programming' started by XcodeNewb, Jul 29, 2009.

  1. macrumors member

    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?

  2. macrumors 68030


    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];
  3. macrumors member

    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!
  4. macrumors regular

    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;

Share This Page