0

I must be missing something really basic here, but I don't even know how to simply describe the problem. I designed my view controller layout in my storyboard, just a bunch of image views, labels, constraints, etc. All static - the only change the code makes is to add round edges to the buttons (UIViews), but I've also tried without that code with no difference made.

Once my segue is followed to the second view controller, it displays like this on the iPhone:

None of the images or text is displaying

I've gotten it to display properly in 2 cases (most of the time):

  1. Waiting. Anywhere between 30sec to 10min. Very unpredictable
  2. Pressing the home button then resuming the app. Sometimes the text still won't show up when I do this.

Either way, this is what it's supposed to look like:

When displaying properly

It doesn't lag or anything as the UI is completely usable even when it's not displaying properly. The images are not very large (biggest is around 300x600) so I doubt that is an issue. Image size also wouldn't account for why the text isn't displaying either. Do UIImageViews load their images asynchrounously?

I thought it might have been that the views needed refreshing because of the exit/resume behaviour. I tried [eachView setNeedsDisplay] with no success.

Any ideas?

-- UPDATE 1 --

Here is an image of my storyboard. As I said, everything is highly static. I have no idea why it's not displaying.

Storyboard

-- Update 2 --

I tried adding my image files to a bundle as suggested:

Bundle

Then tried to reference them pragrammatically in the viewDidLoad method:

// Interface
@property (weak, nonatomic) IBOutlet UIImageView *backgroundImage;

// viewDidLoad
self.backgroundImage.image = [UIImage imageNamed:@"background.png"];

No difference unfortunately.

Ryan
  • 68
  • 7
  • `UIImageViews` load the images synchronously but given the size of your images it shouldnt be problem if the images are on your bundle. try to post the code how you load images. – SpaceDust__ Apr 07 '15 at 19:26
  • Do you set the the images in IB or in code? – dasdom Apr 07 '15 at 19:30
  • Could you post the code you're using from viewDidLoad, and viewDidAppear/viewWillAppear methods if you're using them. Also as dasdom asked, are the images set from within the UIImageView objects on the storyboard, or do you set the images anywhere in code, the prepareForSegue code of previous viewController for example? Any more info you can provide the better. – Jim Tierney Apr 07 '15 at 19:35
  • All the images are set in the storyboard. Image files I just dragged and dropped using the `Images.xcassets` file. – Ryan Apr 07 '15 at 19:45
  • The only code I have in `viewDidLoad` is `self.buttonTimecard.layer.cornerRadius = 20;` `self.buttonTimecard.clipsToBounds = YES;` Then repeated for the other 2 buttons. But as I said, I tried with that code removed and it didn't do anything but get rid of the rounded edges. No other controller methods were overridden. – Ryan Apr 07 '15 at 19:48

2 Answers2

0

I have had this issue using an xcassets file. It tends to work just fine if I just add them to the bundle directly in a group. Check out this thread for some more details. Impossible to load an image in xcassets on bundle

Community
  • 1
  • 1
Dare
  • 2,497
  • 1
  • 12
  • 20
  • Pardon my ignorance with iOS - by adding them to the bundle directly in a group, do you mean creating a new group (folder) in the xcode project and then dragging the images in there? (I'm assuming xcode does all the necessary linking automatically?) – Ryan Apr 07 '15 at 20:02
  • Yes, exactly. You can even go a step further and in your viewController set your imageViews' images explicitly. I.E. UIImage *image = [UIImage imagedNamed:@"some_image_file"]; self.imageView.image = image; The other thing to consider are the images' file format. Xcode very much prefers .png files. Other types are supported but you would need to include the extension like this [UIImage imagedNamed:@"some_image_file.jpg"]; – Dare Apr 07 '15 at 20:09
  • Thanks but it just gave me the same results. – Ryan Apr 07 '15 at 20:27
0

Here's what the problem was for those having the same issue. The previous view controller to the problem screen was a login screen. After receiving credentials, the controller would asynchronously hit the server to validate them. The response from the server was then handled in a callback function called by the networking thread. This meant that the segue was being invoked off of the main thread. Oddly enough, the segue still performed fine I guess it just took a while for the main thread to realize what was happening.

TLDR: Make sure to performSegue on the main thread.

Ryan
  • 68
  • 7