Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

App Puzzle

Hello. I have an animation of the kind used in the Crystal Ball app tutorial. My UiImage *imageView ends on the last frame of the animation.

When the last image is displayed, I would like to disable the button (buttonOne) that starts the animation, and for the animation to reset when another button (buttonTwo) is pressed. Button2 puts the first image of the animation on display, so it is not displaying the last image. So basically, I'm trying to figure out a way to let the user reset the animation.

My question: how do I disable buttonOne when the last image is on display, and enable buttonOne again when the first image is on display?

Here was my first attempt:

- (IBAction)buttonOne:(UIButton *)sender {
if (self.imageView.image == [self.imageView.animationImages lastObject]) {[self.buttonOne setEnabled:NO];}
else {[self.buttonOne setEnabled:YES];}

So far, the button just stays disabled. Any ideas?

1 Answer

Well, here is the answer to my puzzle.

Here was how to reset:

at the end of the buttonOne method I put [self.buttonOne setEnabled:NO]; and at the end of the buttonTwo method (which resets the image) I put [self.buttonOne setEnabled:YES];

Someone pointed out to me that I can't re-enable buttonOne in the buttonOne method because buttonOne has already been disabled.