Note that there are some explanatory texts on larger screens.

plurals
  1. POUnwanted Delay Declaring Image in ImageView within IBAction
    text
    copied!<p><strong>EDIT:</strong> Code altered after recommendation from @llario - no improvement in delay.</p> <p>I am new to objective-C and am having some issue with an unwanted delay loading images in to an imageView. I have started a new project which only assigns an image within the IBAction so when the button is clicked the delay occurs for the image to load for the first time only. Once the images have been used once they work as i want them to - rapid! How can I remove this delay on the first load so that the images load quickly the first time too? It is possible that there will be 12 buttons on my page each with 5 images assigned, meaning 60 images.</p> <p>Striped back h file:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface FCV2ViewController : UIViewController { UIImageView *animalImage; int imageNumber; } - (IBAction)hippoButtonClicked:(id)sender; @end </code></pre> <p>Striped back m file:</p> <pre><code>#import "FCV2ViewController.h" @interface FCV2ViewController () @end @implementation FCV2ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. imageNumber = 0; animalImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 400, 300, 300)]; [self.view addSubview:animalImage]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (IBAction)hippoButtonClicked:(id)sender { if (imageNumber == 0) { animalImage.image = [UIImage imageNamed:@"hippo-00"]; imageNumber++; } else if (imageNumber == 1) { animalImage.image = [UIImage imageNamed:@"hippo-01"]; imageNumber = 0; } } @end </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload