你可以为不同的目标有两个具有相同名称的ViewController实现吗? [英] Can you have two implementations of a ViewController with the same name for differen targets?

查看:111
本文介绍了你可以为不同的目标有两个具有相同名称的ViewController实现吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(这是一个非常大的项目的简化描述)

(This is a simplified description of a very large project)

我有一个有两个目标的XCode项目。两个目标之间的唯一区别是每个目标都有一个不同的viewcontroller实现。

I have an XCode project that has two targets. The only difference between the two targets is there is a different implementation of a a viewcontroller for each target.

视图控制器有一个xib,只是一个带UITextView的简单视图内。我们称之为TextReportViewController。

The view controller has a xib and is just a simple view with a UITextView inside. Let's call it TextReportViewController.

实现A有打印,因此它有一个按钮,允许您打印UITextView的内容。它位于一个名为A的组中。

Implementation "A" has printing, so it has a button that allows you to print the contents of the UITextView. It is in a group called "A".

实现B有电子邮件,因此它有一个按钮,允许您通过电子邮件发送UITextView的内容。它位于一个名为B的组中。

Implementation "B" has email, so it has a button that allows you to email the contents of the UITextView. It is in a group called "B".

目标A在其编译源中包含来自A组和复制包资源的.m文件从组A获取xib。

Target "A" includes in its "compile sources" the .m file from group "A" and "Copy Bundle Resources" takes the xib from group "A".

目标B在其编译源中包含来自组B和复制包资源的.m文件从组B中取出xib。

Target "B" includes in its "compile sources" the .m file from group "B" and "Copy Bundle Resources" takes the xib from group "B".

我在A之后添加了B,也就是说,在我决定我想要另一个目标之前一个。

I added "B" after "A", that is, before I decided I wanted another target things were working with "A".

当我编辑Bxib文件并检查文件的所有者时,我在身份检查器中点击了自定义类的箭头类型转到A的.m文件,而不是B的.m文件。

When I edit "B" xib file and I examine the "file's owner" and in the identity inspector I click on the arrow for the custom class type it goes to "A's" .m file, not "B's" .m file.

当我查看文件所有者的出口时,它是来自A和B。

When I look at the outlets for the file's owner it is a combination of the outlets from "A" and "B".

我在B的xib中添加了一个控件,在助理编辑器中我显示了B的.h文件,我拖了一个按钮来创建一个IBOutlet,然后把它放在A的.h文件中。

I added a control to "B's" xib and in the assistant editor I had the "B's" .h file shown and I drag a button to it to create an IBOutlet and it puts it in "A's" .h file instead.

什么会我必须做的是确保目标A使用A的.h文件和xib文件,目标B使用B的.h文件和xib文件。

What will I have to do to make sure target A is using A's .h file and xib file and target B is using B's .h file and xib file.

注意当我添加了目标B,它创建了一个名为B的文件夹。所以文件的位置如下:

Note that when I added target "B" it made a folder called "B". So the files are located like this:

Root:

TextReport:

    TextReportViewController.m

    TextReportViewController.h

    TextReportViewController.xib

B:

    TextReport:

        TextReportViewController.m

        TextReportViewController.h

        TextReportViewController.xib

此外,当我编辑Bxib文件并显示助理编辑器并选择自动以显示.h和.m文件时,它显示四,两个.h文件和两个.m文件。

Also when I am editing the "B" xib file and I show the assistant editor and select "automatic" to show the .h and .m files, it shows four, the two .h files and the two .m files.

推荐答案

我怀疑你不能有这种设置。即使您的每个目标使用VC的不同副本,您也必须在Xcode项目中同时拥有同名文件的副本。这是混乱开始的时候。在IB中指定xib的所有者时,提供类的名称,但不提供定义它的文件的路径。所以你无法真正知道正在使用哪两个文件。

I suspect you can't have this kind of setup. Even though each of your targets uses a different copy of your VC, you have to have both copies of the files with the same name in your Xcode project. This is when the confusion begins. When you specify the owner of a xib in IB, you provide the name of the class, but not the path to the file where it's defined. So you can't really know which of the two files is being used.

我建议为不同的目标使用不同的名称。

I'd suggest using different names for different targets.

这篇关于你可以为不同的目标有两个具有相同名称的ViewController实现吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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