Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5957515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:24:40+00:00 2026-05-22T18:24:40+00:00

I need to toggle a specific amount of times between two (or maybe later

  • 0

I need to toggle a specific amount of times between two (or maybe later on more) pictures after a button was pressed, and wait a second or two for the change. When a stop-button is pressed at any time, the toggling should stop. My code by now looks like this

IBOutlet UIImageView *exerciseView;

- (void) repetitionCycle {

    stopButtonPressed = NO;
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 

    for (NSInteger counter = kRepetitions; counter >=0; counter--) {
        exerciseView.image = [UIImage imageNamed:@"blue.jpg"];  
        [NSThread sleepForTimeInterval:kSleepDuration];                                                                 
        if (stopButtonPressed) {break;}     

        image = [UIImage imageNamed:kExerciseEndingPosition];                                                           
        exerciseView.image = [UIImage imageNamed:@"image1.jpg"];
        [NSThread sleepForTimeInterval:kSleepDuration];     

        if (stopButtonPressed) {break;}     
    }

    self.stopRepetitionCycle;
    [pool release];

}

exerciseView is
Besides other things, in stopRepetitionCycle I just set stopButtonPressed to YES, so it stops after it finished the “for” for the first time.
It does count down, it does stop after one cycle, but it doesn’t change the picture.

While fiddling around, I set the initial picture via IB, so it finally displayed ANYTHING.. The fun part, when I hit the stop button in the right moment, the second picture is shown. So I guessed I need to set the view manually every time the image should toggle. But

        [self.exerciseView addSubview:image];

gives me the error

Incompatible Objective-C types "struct UIImage *", expected "struct UIView *" when passing argument 1 of "addSubview:" from distinct Objective-C type

Also

        [self.exerciseView.image addSubview:image];

doesn’t do the job and gives me a

UIImage may not respond to addSubview

Any idea what I have to do here?

Thank you very much!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:24:41+00:00Added an answer on May 22, 2026 at 6:24 pm

    Use UIImageView. It has built-in support for this.

    imageView.animationImages = [NSArray arrayWithObjects:[UIImage imageNamed:@"blue.jpg"], [UIImage imageNamed:@"image1.jpg"], nil];
    imageView.animationDuration = kSleepDuration * [imageView.animationImages count];
    

    Wire this function to the start button

    - (IBAction) startAnimation {
        [imageView startAnimating];
    }
    

    and this to the stop button

    - (IBAction) stopAnimation {
        [imageView stopAnimating];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some HTML that I need to toggle between two structures - one
I need a button in Flash/AS3 that toggles between on and off. So I
I need to toggle existing android contacts to favourite. I have a toggle button
I need to bind two events in my backbone.js -view in order to toggle
I'm in need to toggle divs from a dropdown select option box. I'd like
I'm trying to make the code below reusable. I need multiple toggle buttons in
I need to toggle an element ONLY if it is not disabled. jQuery(#sbutton).toggle( function
I had this working fine while using toggle, but I need to make these
For a FAQ i need a toggle panel similiar to this one: http://roshanbh.com.np/examples/exapandable-panel/ One
I need to capture the KeyUp event in my form (to toggle a full

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.