NSMutableArray of UIButton objects

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

  1. macrumors member

    Joined:
    Feb 6, 2009
    #1
    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
     
  2. macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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];
     
  3. thread starter macrumors member

    Joined:
    Feb 6, 2009
    #3
    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

    Joined:
    Jul 27, 2009
    Location:
    Palo Alto, CA
    #4
    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;
    
     

Share This Page