简体   繁体   English

View Controller无法正确显示

[英]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. 我在情节提要中设计了视图控制器布局,只是一堆图像视图,标签,约束等。所有静态操作-代码所做的唯一更改是在按钮(UIViews)上添加了圆形边缘,但我也尝试过没有那个代码就没有区别。

Once my segue is followed to the second view controller, it displays like this on the iPhone: 一旦我的选择进入第二个视图控制器,它就会在iPhone上显示如下:

没有图像或文字显示

I've gotten it to display properly in 2 cases (most of the time): 我已经在2种情况下(大多数情况下)正确显示了它:

  1. Waiting. 等候。 Anywhere between 30sec to 10min. 30秒到10分钟之间的任何时间。 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. 它不会滞后,也不会有任何问题,因为即使显示不正确,UI也可以完全使用。 The images are not very large (biggest is around 300x600) so I doubt that is an issue. 图像不是很大(最大约为300x600),所以我怀疑这是一个问题。 Image size also wouldn't account for why the text isn't displaying either. 图像大小也无法说明为什么文本也不显示。 Do UIImageViews load their images asynchrounously? UIImageViews是否会意外地加载其图像?

I thought it might have been that the views needed refreshing because of the exit/resume behaviour. 我认为可能是因为退出/恢复行为而需要刷新视图。 I tried [eachView setNeedsDisplay] with no success. 我尝试[eachView setNeedsDisplay]失败。

Any ideas? 有任何想法吗?

-- UPDATE 1 -- -更新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 -- -更新2-

I tried adding my image files to a bundle as suggested: 我尝试按照建议将图像文件添加到包中:

束

Then tried to reference them pragrammatically in the viewDidLoad method: 然后尝试在viewDidLoad方法中以viewDidLoad方式引用它们:

// 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. 我使用xcassets文件遇到此问题。 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 无法在捆绑软件的xcassets中加载图像

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. 这意味着segue正在主线程之外被调用。 Oddly enough, the segue still performed fine I guess it just took a while for the main thread to realize what was happening. 奇怪的是,segue仍然表现不错,我猜主线程花了一段时间才意识到发生了什么。

TLDR: Make sure to performSegue on the main thread. TLDR:确保在主线程上执行Segue。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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