Storyboard UIImageview problem

Discussion in 'iOS Programming' started by digitalfortress, Apr 21, 2012.

  1. digitalfortress, Apr 21, 2012
    Last edited by a moderator: Apr 21, 2012

    digitalfortress macrumors newbie

    Joined:
    Nov 9, 2009
    #1
    Hello everybody,

    I'm new to iphone/ipad development so please bare with me :)

    I have multiple UIImageviews on my storyboard already assigned to images but all of them are hidden, all i want to do is show the UIImageview using its tag based on the button i press (which happens to have the same tag)

    here is the code
    in the .h file
    Code:
     IBOutlet UIImageView *hintImage;
    
    @property (nonatomic, retain) IBOutlet UIImageView *hintImage;
    
    in the implementation file
    @synthesize hintImage;
    
    -(IBAction)appear:(id)sender{
              int imageIndex = ((UIButton *)sender).tag;   	
             [hintImage viewWithTag:imageIndex];	    
             hintImage.hidden = NO;
    }
    
    here is what happens:
    if i just leave it like this and run, nothing happens when i press the button

    if i make a reference in the storyboard from any UIImageview to hintImage, only one reference it allowed, i cannot reference the other image views to hintImage, so accordingly in runtime when i click the button only the referenced imageview appears no matter which button i choose

    can anybody tell me how to fix it and i if i have a wrong logic!!
     
  2. digitalfortress thread starter macrumors newbie

    Joined:
    Nov 9, 2009
  3. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #3
    you don't need the IBOutlets, you just need to create new pointers, and assign them to the viewWithTag:index blah.
    Because the logic is "quite good", but the pointer is wrong (for neat coding).
    You need to assign a new UIImageView pointer to viewWithTag:indexthingy.
    This will recreate the pointer to that object, and you can set it hidden :)
     

Share This Page