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

  • Home
  • SEARCH
  • 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 6941911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:56:48+00:00 2026-05-27T12:56:48+00:00

been working on an app and have been studying the questions available here but

  • 0

been working on an app and have been studying the questions available here but no luck in finding something similar to resolve my problem.

I have an array setup with 4 images and I’m trying to change to a different image every time the image is touched in sequence and then back to first after last image displayed.

For example: image1 “touch” => image2 “touch” => image3 “touch” image4 “touch” => image1…..

The image won’t change unless “touched”.

My array is setup as:

    -(void) viewDidLoad {
        imageArray = [[NSArray alloc] initWithObjects:
                      [UIImage imageNamed:@"image1.png"],
                      [UIImage imageNamed:@"image2.png"],
                      [UIImage imageNamed:@"image3.png"],
                      [UIImage imageNamed:@"image4.png"],
                      nil];

I then display the first image with the following:

    imageView.image = [imageArray objectAtIndex:0];

Then, I’m able to successfully change between two images with the following code:

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
       UITouch *touch = [[event allTouches] anyObject];
       NSLog(@"'Touches Began");

       if ([touch view] == imageView) {
           imageView.image = [imageArray objectAtIndex:1];
           NSLog(@"Image touched and changed");
       }

Now, because I want imageView display more than two changes, I tried to use if statement inside a for loop with no luck:

    int touchCount = 0;
    for (touchCount = 1; touchCount < 4; touchCount++) {
        if ((touchCount < 4) && ([touch view] == imageView)) {
            imageView.image = [imageArray objectAtIndex:touchCount];
            NSLog(@"Touch Count = %d", touchCount);
        }
    }

When ran, the debugger shows “Touch Count = 0” and then just crash and exits back into the home screen. Can anybody please help on this problem? Is my concept wrong?

  • 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-27T12:56:49+00:00Added an answer on May 27, 2026 at 12:56 pm

    Have an integer as an instance variable which stores which image is being displayed. Set this to 0 on viewDidLoad.

    When a touch is registered on the image view, increment the integer. If the value equals the count of your image array, set it back to 0.

    Set the image to the element of your image array indicated by the integer value:

    // touch registered on image
    currentImage++;
    if (currentImage == [imageArray count])
        currentImage = 0;
    
    imageView.image = [imageArray objectAtIndex:currentImage];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on a small php app (400K total). But in the
I have been working on the app engine for some time, and this problem
I have been working on an app for a couple of months now, but
I have an MVC app that I have been working on but I seem
I have been working on an app which requires finding the height and width
I have been working hard in this app and have come into a problem
I have an app that I've been working on, but now I need to
I have been working on an app where I have successfully shown my location
I have been working on this app for at least 3-4 months and just
I have been working on an iOS App for sometime now and its almost

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.