[英]Interface builder changes do not reflect in runtime
After some months of not opening this project, when I opened it today, every new view I add to my ViewController's interface in the corresponding Storyboard is not reflected.在几个月没有打开这个项目之后,当我今天打开它时,我在相应的 Storyboard 中添加到我的 ViewController 界面的每个新视图都没有反映。 For instance, changing a button background does not reflect in the app at runtime.
例如,更改按钮背景不会在运行时反映在应用程序中。
Also, adding new views and referencing them through a @IBOutlet doesn't work as well.此外,添加新视图并通过 @IBOutlet 引用它们也不起作用。 I get a nil view reference on my
viewDidLoad
.我在
viewDidLoad
上得到了一个 nil 视图参考。 Weirdly enough, all the views I had before, and am accessing on the viewDidLoad are not nil.奇怪的是,我之前拥有的所有视图以及在 viewDidLoad 上访问的所有视图都不是零。 Only the new views I add have this problem.
只有我添加的新视图有这个问题。
I have tried clearing the DerivedData folder and simulator caches but I ran out of stuff to try out.我已经尝试清除 DerivedData 文件夹和模拟器缓存,但我用完了可以尝试的东西。 Anyone else having this issue?
还有谁有相同的问题吗?
To sum it all, every change I do on the interface builder now is to being applied to my view.总而言之,我现在在界面构建器上所做的每一个更改都是为了应用到我的视图中。
I am running Xcode 12.5.我正在运行 Xcode 12.5。
EDIT: I tried adding a UILabel programmatically and it works.编辑:我尝试以编程方式添加 UILabel 并且它有效。 So, this is something that is wrong with how the storyboard creates the view reference in the ViewController.
因此,storyboard 在 ViewController 中创建视图引用的方式有问题。 I still need help tho.
我仍然需要帮助。
One scenario in which that might happen is this:可能发生这种情况的一种情况是:
Have you checked the constraints?你检查过约束吗? any of them are overlapped/ clipped or not defined any constraints at all?
它们中的任何一个都被重叠/剪裁或根本没有定义任何约束? (In case of new Views and not the BG color)
(如果是新视图而不是 BG 颜色)
I found the issue after some hours.几个小时后我发现了这个问题。 What led to this was that somehow, when I localized the storyboard in the past, XCode created one storyboard per language instead of just creating 2.string files for each language.
导致这种情况的原因是,当我过去本地化 storyboard 时,XCode 为每种语言创建了一个 storyboard,而不是为每种语言创建 2.string 文件。 So this did the trick:
所以这成功了:
Before:前:
After:后:
Problem solved!问题解决了! Thank you all
谢谢你们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.