故事板会自动复制到新项目中 [英] The storyboard is automatically copied to the new project

查看:35
本文介绍了故事板会自动复制到新项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Xcode 中有一个项目,我们将其命名为 A,其中我有一个故事板和几个视图.我只需要A 项目的一部分.因此,我创建了一个新项目 B,并使用 xib 创建了一个新的 UIViewController,并从项目 中复制了两个 UIViewsA 到 B.现在看起来像这样,其中 RPM DisplaySpeed Display 从 A 复制到 B(通过从 xib 拖动).

I have a project in Xcode, lets name it A, in which I have a story board and several views. I only need part of project A. Hence, I made a new project, B, and made a new UIViewController, with xib, and copied the two UIViews from project A to B. It looks like this now, where RPM Display and Speed Display are copied (by dragging from xib) from A to B.

AnalogDisplayContainer 属于PD_AnalogDisplayContainer 类,我们在PD_AnalogDisplayContainer 类中有两个插座:

AnalogDisplayContainer belongs to the class PD_AnalogDisplayContainer, and we have two outlets in class PD_AnalogDisplayContainer:

@property (nonatomic,assign) IBOutlet PD_AnalogDisplay* speedDisplay;
@property (nonatomic,assign) IBOutlet PD_AnalogDisplay* rpmDisplay;

它们连接到 xib 中的各个视图.(我们在项目 A 中有完全相同的代码.)这些 UIViews 也有一些 UILabels,它们会在项目 中自动复制B,我也需要它们.您可以在这里看到它们:

which are connected to the respective views in xib. (We have exactly the same code in project A.) These UIViews have some UILabels as well, which are automatically copied in project B, and I need them as well. You see them here:

到此为止,我所做的描述.现在,问题:我在 PD_AnalogDisplay 班上有三个插座.

Up to here, the description of what I did. Now, the problem: I have three outlets in class PD_AnalogDisplay.

@property (nonatomic, assign) IBOutlet UILabel* unitLabel;
@property (nonatomic, assign) IBOutlet UILabel* digitalIntegerValue;
@property (nonatomic, assign) IBOutlet UILabel* digitalFloatValue;

然而,很奇怪的是,当我点击这些插座旁边的小点时,它会显示与故事板的连接,

However, so strangely, when I click on the small point beside these outlets, it shows me the connections to story board,

当我点击连接时,我会看到整个故事板和项目 A 的视图.

and when I click on the connection, I see the whole storyboard and views from project A.

此外,当我点击 xib 时,这些连接不会显示.

In addition, these connections are not shown when I click on xib.

我在项目 B 中搜索,没有故事板,或者我在上图中看到的所有这些东西,以代码的形式.所以我不知道这一切来自哪里.我收到运行时错误:加载了RPMViewController"笔尖,但未设置视图插座.

I searched in project B, there is no storyboard, or all these things I see in the previous picture, in form of code. So I don't know where it all come from. And I get the run time error: loaded the "RPMViewController" nib but the view outlet was not set.

推荐答案

是的,无论您在哪里复制它,它都会带来以前的参考.这是因为项目 A 和 B 中的类名相同.在项目B中创建除项目A中的类名以外的类名或稍微更改变量名.

Yes, it brings previous reference wherever you copy it. It is happening because the class name is same in project A and B. Create class name in project B other than class name in project A or slightly change variable name.

将该类分配给您的 xib 文件.您必须从 xib 文件重新创建 IBOutletes.只需复制接口组件,而不是 .h 文件中的代码.

Assign that class to your xib file. You must recreate the IBOutletes from xib file. Just copy the interface components not the code in .h file.

观察:

  • 当我将项目 A 移动到另一个位置时,引用会被破坏.

这篇关于故事板会自动复制到新项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆