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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T04:17:37+00:00 2026-05-30T04:17:37+00:00

I have an UIImageView with a method to change the image it displays. It

  • 0

I have an UIImageView with a method to change the image it displays. It works fine, if the method is triggered from a touch event received by the UIImageView itself, but the same method fails to update the UIImageView, if called from another object, which triggered the touch event. I have an NSLog call in the method in question and thus can see, that the method is called in both cases. But only in one case I can see the actual change of the image in the other case the view is not updated.
When it works, I do not need to setNeedsDisplay or setNeedsLayout, but that is what I tried to fix the problem. Setting needsDisplay and needsLayout in the UIImageView as well as its superview. To no avail. I can see, that the image is actually changed, if I rotate the device, which causes a refresh and I see, that the UIImageView indeed changed.

The superview calls the method eventAtLocation: on an OutletCollection using makeObjectsPerformSelector:withObject:

It sure looks like an embarrassing mistake on my part, but I can’t figure it out since hours. I am running out of ideas what to try 🙁

Here’s the code in question:

- (void)eventAtLocation:(NSValue *)location
{
    CGPoint loc = [self.superview convertPoint:[location CGPointValue] toView:self];
    if ([self pointInside:loc withEvent:nil]) {
        if (!self.isAnimating) {
            [self autoSwapImage];
        }
    }
    else{
        if (self.isAnimating) {
            [self cancelAnimation];
        }
    }
}

- (void)cancelAnimation
{
    self.isAnimating = NO;
    [NSObject cancelPreviousPerformRequestsWithTarget:self];
}

- (void) swapImage
{
    currentImage++;
    if (currentImage > numberOfImages)
        currentImage = 1;

    NSLog(@"set image to %i", currentImage);
    self.image = [UIImage imageNamed:[NSString stringWithFormat:@"img_%i.jpg", currentImage]];
    [self setNeedsDisplay];
}

- (void) autoSwapImage
{
    self.isAnimating = YES;
    [self swapImage];
    [self performSelector:@selector(autoSwapImage) withObject:self afterDelay:0.1];
}

// The following works, but if eventAtLocation: is called form the superview swapImage gets called (-> NSLog output appears), but the view is not updated
– (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//[self autoSwapImage];
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    //[NSObject cancelPreviousPerformRequestsWithTarget:self];
}
@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-30T04:17:39+00:00Added an answer on May 30, 2026 at 4:17 am

    It looks like you aren’t actually setting the UIImageView’s image, you are just setting self.image. You need to do something like

    self.myImageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"img_%i.jpg", currentImage]];
    

    Also you’ll want to put a check in that [UIImage imageNamed:] actually is returning an image, and that its not nil.

    UIImage* image = [UIImage imageNamed:@"someImage"];
    if(!image){
      NSLog(@"%@",@"Image Not Found");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problems updating the image of an UIImageView from within a method that
I Have a UIScrollview with a UIImageView inside where I scroll from an image
I have a UIImageView whose image I want to change depending on user input.
I have an UIImageView which I want to rotate a little bit, but I
I have a UIImageView which has a png image sequence loaded into it. My
I have a UIImageView showing a image that is larger than it's frame. It's
I have an UIImageView and taking the raw touch input. I need to check
I have a UIImageView that starts off with an image (loading.png) specified in IB.
I have a UIImageView object in one of my classes, but I need to
I have applied following code to my application to change the navigation bar image.

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.