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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:18:08+00:00 2026-06-10T13:18:08+00:00

Okay, I have a problem with my code. I want to make some sort

  • 0

Okay, I have a problem with my code. I want to make some sort of grid like game using imageViewers, but when the method that changes the pictures which the imageViewers how, it only updates the screen/imageviewers once it is finished executing, not when the line that does it is actually executed. I has a method with an infinite loop in it and it changes the pictures of the imageViewers as you press buttons. The buttons call methods which change a boolean variable to true, so the main game loop knows whats been pressed by constantly checking if certain variables are true. But because the game loop never ends the screen is never updated. Is there a way to update what’s on the screen during execution?

I am using this code to change the imageViewers contents:

     UIImage * white = [UIImage imageNamed: @"White.png"];
     UIImage * blue = [UIImage imageNamed: @"Blue.png"];
     int tagInt=1;
     for (int y = 0;y<10;y++){
         for (int x = 0;x<10;x++){
             UIImageView *imageView;
             imageView = [[UIImageView alloc] initWithImage:white];                 imageView.frame =CGRectMake(x*32,y*37,32,37);
             imageView.image = white;
             imageView.tag=tagInt;
             [self.view addSubview:imageView];
             tagInt++;
         }
     }
     for (int u = 1;u<20;u++){
         [NSThread sleepForTimeInterval:(1)];   
         UIImageView *g = (UIImageView*)[self.view viewWithTag:u];
         g.image =blue;
     }

This is a contrived example, because my actual code is too long, but has the same problem. It only updates on-screen after the last for loop (this delays/thread-sleep commands) finishes, not as the lines of code execute.

EDIT: Here is the project if you want any context: https://www.dropbox.com/s/cvefllnhgj0tp6g/Stacker.zip

  • 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-06-10T13:18:09+00:00Added an answer on June 10, 2026 at 1:18 pm

    In iOS, all UI related stuff is done in the main (UI) thread. If you have an operation that blocks the ui thread – which means, it keeps the thread busy as you do – no view update will occur.
    So you will have to change your code that way, that you have a “updateView” method which changes the image views’ content. This method will have to be called on a regular base, e.g. by using an NSTimer instance: https://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/nstimer_Class/Reference/NSTimer.html

    Assuming, the code to update your view is named “updateView”, you could define a timer like this:

    NSTimer *timer;
        timer = [NSTimer scheduledTimerWithTimeInterval: 1
                            target: self 
                            selector:@selector(updateView:) 
                            userInfo: nil 
                            repeats: YES];
    

    So the timer would call your updateView method every second and would not block the main thread which again would allow the changes you made to the view to become visible.

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

Sidebar

Related Questions

Okay, so I have some code that worked fine in PHP4 but since upgrading
Okay so i have a semi weridish problem with re.sub. Take the following code:
Well, code speaks more (I have hard-coded some things, to isolate the problem and
Okay, so I have the weirdest problem right now. My code is fine! It
Okay I'm having a problem. I have a social networking site and have some
Okay I have seen some very similar questions here but none seem to be
Okay. I want to have two threads running. Current code: public void foo() {
I have a problem with (for me to complicated) MySql query. Okay, here is
Okay, so here's my problem: I have a list of members on a website,
Okay, so I have another question on a prolog homework problem I am struggling

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.