简体   繁体   English

界面构建器更改不会反映在运行时

[英]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:可能发生这种情况的一种情况是:

  1. You have multiple targets with different sets of storyboards for each target您有多个目标,每个目标都有不同的故事板集
  2. You modify a storyboard that is not accessible in the current target that you build您修改了在您构建的当前目标中不可访问的 storyboard

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.

相关问题 在Interface Builder中反映UIView图层的属性更改 - Reflect changes in UIView layer's properties in Interface Builder Interface Builder,IOS 6上的框架更改 - Interface Builder, frame changes on IOS 6 UITextView在运行时比在界面构建器中更宽 - UITextView wider at runtime than in interface builder 什么是Interface Builder中的“用户定义的运行时属性”? - What are “User Defined Runtime Attributes” in Interface Builder? 为什么 UITableViewCells 中的 UIButtons 会丢失它们在运行时设置的值并默认返回到它们的 Interface Builder 值? - Why do UIButtons inside UITableViewCells lose their values which were set at runtime and default back to their Interface Builder values? NavigationBar在运行时隐藏View,但在Interface Builder中不隐藏 - NavigationBar hides View while runtime but not in Interface Builder 这些设置在 Interface Builder 中有什么作用? - What do these settings do in Interface Builder? 确定Interface Builder中UI元素的可用运行时属性 - Determining available runtime attributes for a UI element in Interface Builder 如何在 Interface Builder 中存储键/值并在运行时访问它们? - How to store key/value in Interface Builder and access them during runtime? iOS-在运行时获取由Interface Builder创建的UIView框架 - iOS - get frame of UIView at runtime which was created with Interface Builder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM