简体   繁体   中英

View Controller not Displaying Correctly

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:

没有图像或文字显示

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:

正确显示时

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.

故事板

-- Update 2 --

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

束

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM