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 6931927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:38:26+00:00 2026-05-27T11:38:26+00:00

I’m playing around with a simple test app that just loops through 10 images

  • 0

I’m playing around with a simple test app that just loops through 10 images and displays each one to the view. The next image will be displayed after the user clicks a button. The problem I am having is the view is never appearing (image or button). When I take out the button press clause, the code runs and the last image is displayed. continueRunningScript is initially YES.

@interface ViewController : UIViewController <UIAlertViewDelegate>
{
    BOOL continueRunningScript;
    UIButton *wrongButton;
    UIImageView *imageView;
}

// ...

@end

@implementation ViewController

// ...

- (void) xxx {

    for (int i = 0; i<10; i++) {

        while (continueRunningScript == NO) {
            // Stay here until button is pressed.
        }

        UIImage *testImg = ... // code to load the image at index i

        imageView = [[UIImageView alloc] initWithImage: testImg];

        [self.view addSubview:imageView];

        wrongButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [wrongButton addTarget:self 
                        action:@selector(incorrectResultButtonPress:)
              forControlEvents:UIControlEventTouchUpInside];
        [wrongButton setTitle:@"Wrong Result?" forState:UIControlStateNormal];
        wrongButton.frame = CGRectMake(80.0, 310.0, 160.0, 40.0);
        [self.view addSubview:wrongButton];

        continueRunningScript = NO;

        [testImg release];
    }
    [imageView release];
    [wrongButton release];
}

// button press handling...

// UIAlertViewDelegate
- (void) alertView: (UIAlertView *)actionSheet clickedButtonAtIndex: (NSInteger)buttonIndex {

    // The user clicked one of the Yes/No buttons
    if (buttonIndex == 0) // Yes
    {
        UIAlertView *thankyouAlert = [[UIAlertView alloc] initWithTitle:@"Thank You"
                                                                message:@"Thanks for the feedback!"
                                                               delegate:self
                                                      cancelButtonTitle:nil
                                                      otherButtonTitles:nil];
        [thankyouAlert show];
        // Call performSelector delegate method of NSObject to call class method dismissAlertView 
        [self performSelector:@selector(dismissAlertView:) withObject:thankyouAlert afterDelay:2];
        [thankyouAlert release];
        [wrongButton removeFromSuperview];
        continueRunningScript = YES;
    }
}

// ...

@end
  • 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-27T11:38:27+00:00Added an answer on May 27, 2026 at 11:38 am

    I’m making the assumption that you aren’t doing this on a background thread or anything. If you are, then you should be aware that UIKit is only designed to be used from the main thread.

    while (continueRunningScript == NO) {
        // Stay here until button is pressed.
    }
    

    This will not work the way you want it to. It will enter an infinite loop. The thread of execution will not progress past this point to process any input events, so that variable will never get a chance to be set to YES.

    You have to remember that all of the user interface code will run after you exit from your method. If you take the pure out, then you’re looping through all the images that are added, then the user interface is updated. That’s why you only see the last image – the others were added too, but they are underneath the top-most (last) one.

    If you want a new image to be shown every time the user taps a button, then you should have an instance variable that keeps track of which image is the current one, and write a method to update this variable and show the next image. In almost all circumstances, a busy loop like the above is wrong.

    Also, you should be aware that you don’t have to add a new UIImageView every time you want to display a new image. You can simply update the image property for an existing image view to change which image it is displaying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I am doing a simple coin flipping experiment for class that involves flipping a
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build

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.