views:

711

answers:

5

Hey again,

I have the following code:

visitSite.hidden = YES;

For some reason, when I click a UIButton and call this piece of code, the visitSite button does not hide.

The code is within this block:

-(IBAction)welcomeButtonPressed:(id)sender {
  [UIButton beginAnimations:@"welcomeAnimation" context:NULL];
  [UIButton setAnimationDuration:1.5];
  [UIButton SetAnimationDidStopSelector:@selector(nowHideThisSiteButton:finished:context:)];
  [UIButton setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
  ((UIView *)sender).hidden = YES;
  [UIButton commitAnimations];
}

and the stop selector below:

-(void)nowHideThisSiteButton:(NSString *)animationID finished:(BOOL *)finished context:(void *)context {
  visitSite.hidden = YES;
}

I've also tried [visitSite setHidden:YES]; and that fails as well. ALSO I've noticed that the setAnimationDidStopSelector does not get called at all.

Also, visitSite (when NSLogged) equals:

<UIButton: 0x1290f0; frame = (0 0; 320 460); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x1290f0>>

visitSite.hidden (when NSLogged) equals: NULL

Any more ideas? :(

A: 

Could it be that you wrote:

visitWebsite.hidden = YES;

instead of:

visitSite.hidden = YES;

?

What about setting your buttons alpha to 0, does that work?

ahmet emrah
Apologies, it's because I can't copy paste between the Mac and my PC. The code is right now - still doesn't work :(
Neurofluxation
visitSite.alpha = 0; Doesn't work either :(
Neurofluxation
A: 

Have you double-checked the bindings in Interface Builder? Did you remember to connect the button to the controller?

Try putting a breakpoint on visitSite.hidden = YES; and make sure that visitSite isn't null or set to something unexpected.

kubi
Ok, I NSLogged the lot and visitSite = the button in question and visitSite.hidden = NULL.
Neurofluxation
Everything is connected properly in IB as well.
Neurofluxation
if the button is NULL, something is not hooked up right.
Ben Gottlieb
I have updated my question from this point :)
Neurofluxation
A: 

Your animationDidStopSelector definition is incorrectly defining the finished: argument type as a pointer to a boolean (BOOL *) rather than just a boolean (BOOL). I believe this is your problem.

Victorb
I removed the *pointer, however this hasn't changed any functionality :(
Neurofluxation
+1  A: 

you could try [visitSite removeFromSuperview];

Remover
+3  A: 

There are a few mistakes in your code.

  1. The hidden property of UIView is NOT animatable. When this animation block runs, your button will vanish, but it will not fade/animate. The appropriate way to fade out a UIView is to animate its alpha property from 1.0 to 0.0 like this:

    myView.alpha = 1.0;
    [UIView beginAnimations:@"Fade" context:NULL];
    myView.alpha = 0.0;
    [UIView commitAnimations];

    Here is a list of animatable UIView properties

  2. setAnimationDidStopSelector does not get called because you have not set the animation delegate. You have properly specified a didStopSelector, which tells the UIView class what message to send when animation is complete. However, you haven't specified what to send this message to. The animation block has no idea about your object. Just add this line inside the animation block:

    [UIView setAnimationDelegate:self];

    (Replace self with whatever object you want to receive the didStopSelector)

  3. As others has stated, your button is nil because it hasn't been hooked up properly in Interface Builder. In your .h file, you should have @property (nonatomic, retain) IBOutlet UIButton * visitSite;. Then in Interface Builder, click your controller, switch to the Connections display, and drag the open circle thing over to your button. That should do it. See the Interface Builder help guide for more info on that.

adkap