Resolved iOS 8.4: UIImage shows up after breakpoint. How do I fix this?

Discussion in 'iOS Programming' started by moonman239, Sep 18, 2015.

  1. moonman239, Sep 18, 2015
    Last edited: Sep 24, 2015

    moonman239 macrumors 68000

    Joined:
    Mar 27, 2009
    #1
    I have an AVPlayer in an app I'm building that absolutely mustn't start playing until after a UIImage is shown. I'm finding, though, that it sometimes starts playing before the image. I created another project just to see what would happen if I broke after setImage, and the result was quite surprising: the image did not get set until after I continued past the breakpoint. Here's my code:

    Code:
    - (void)viewDidAppear:(BOOL)animated
    
    {
    
        [superviewDidAppear:animated];
    
        NSString *fileName = @"nottelling";
    
        UIImage *image = [UIImageimageNamed:fileName];
    
        [self.imageViewsetImage:image];
    
        NSLog(@"image: %@",image);
    
    }
    
    Will someone please help? Thanks.

    The Solution That Solved My Problem

    I checked the sizes (in pixels) of the images, and they were way too big. Bigger size = greater processor load. Therefore, using an image manipulation program, I reduced the sizes.
     
  2. 1458279 Suspended

    1458279

    Joined:
    May 1, 2010
    Location:
    California
    #2
    The code is incomplete, it doesn't show the actual AVPlayer, but I assume you are loading, setting the image then an AVPlayer.

    I would start by finding if they are on different threads. Maybe even set the AVPlayer as part of a completion block or seek confirmation of the image being shown before the AVPlayer is started.

    You can also examine the resources used to start the AVPlayer (file loading, buffering, display settings,...) Then see if there is some kind of "ReadToPlay" call or block.
     
  3. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #3
    You should probably try to show the image earlier, in viewDidLoad or viewWillAppear. Or build the image in viewDidLoad but assign it later. I would expect that an image loaded by UIImage.imageNamed would load instantly. imageNamed goes through the application imageCache and UIImage has the ability to be purged and reloaded from/to memory in response to memory warnings. I don't believe there's any way to tell if the image is loaded or visible though.
     
  4. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #4
    I found the solution. Check the image res, and make sure it's appropriate for the rendering device. Images are drawn in a run loop.
     
  5. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #5
    imageNamed only loads images from the app bundle so you should know at compile time if you have the right resolutions. I guess the problem was that the resolution was too high?
     
  6. moonman239 thread starter macrumors 68000

    Joined:
    Mar 27, 2009
    #6
    You guessed correctly.
     

Share This Page