如何在编译时使用不同的接口声明,而不会混淆Interface Builder [英] How to use different interface declarations at compile time without confusing Interface Builder

查看:218
本文介绍了如何在编译时使用不同的接口声明,而不会混淆Interface Builder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有多个版本的应用程序,例如付费和免费版本,我想有不同的接口,这取决于哪个版本,它似乎混淆Interface Builder。

If I have multiple builds of my app, paid and free versions, for example, and I want to have different interfaces depending on which build, it seems to confuse Interface Builder.

例如:

// MyViewController.h
#ifdef FREE
@interface MyViewController : NSObject <UIActionSheetDelegate, ADBannerViewDelegate>
#else
@interface MyViewController : NSObject <UIActionSheetDelegate>
#endif
{
    IBOutlet UILabel* myLabel;
}
- (IBAction) myAction:(id)sender;

当我在IB中加载MyViewController.xib时,它在信息窗口中显示警告, 'File'Owner'的myLabel'''''''''连接到'我的视图',但'myLabel'不再定义在My​​ViewController。

When I load up MyViewController.xib in IB, it shows warnings in the Info window like "The 'myLabel' outlet of 'File's Owner' is connected to 'My View' but 'myLabel' is not longer defined on MyViewController."

有办法做到这一点为了不混淆IB?

Is there a way to do this so as not to confuse IB?

我假设另一个选项是只是不#ifdef它,并有一个定义所有的构建。如果我使用我的控制器符合ADBannerViewDelegate(需要iOS 4)和我部署在iOS 3.2上做什么会发生什么?如果有效,也许没有问题...

I suppose the other option is to just not #ifdef it, and have one definition for all builds. What happens if I build with my controller conforming to ADBannerViewDelegate (which requires iOS 4), and I deploy on iOS 3.2? If that works, maybe there's no issue...

推荐答案

我还没有找到办法获得IB了解你正在使用的结构(我试图用一个付费/免费的应用程序,我在过去做)。这是我解决我的问题:

I haven't been able to figure out a way to get IB to understand the structure you're using (I tried to do it with a paid/free app I made in the past). This is how I solving my problem:

我没有使用条件编译在我的@interface定义。我只是定义类作为正常,如果它是付费,非广告版本。让我们称之为MyPaidViewController。

I didn't use the conditional compilation in my @interface definition. I just defined the class as normal as if it was the paid, non-ad version. Let's call it MyPaidViewController.

@interface MyPaidViewController : UIViewController <UIActionSheetDelegate> {

然后我创建了MyPaidViewController的子类,类似:

Then I created a subclass of MyPaidViewController which was the for the free version. Something like:

@interface MyFreeViewController : MyPaidViewController <ADBannerViewDelegate> {

由于我通常需要为我的免费版本使用不同的xib (因为我不得不移动东西,以便为广告空间)我只需要付费的xib使用MyPaidViewController作为文件的所有者和我的免费xib使用MyFreeViewController作为文件的所有者。

Since I usually needed to use a different xib for my free version than I did for my paid version (because I had to move stuff around in order to make room for the ads) I would just have the paid xib use MyPaidViewController as File's Owner and my free xib use MyFreeViewController as the File's Owner.

Interface Builder将会从超级类中看到IBOutlet,所以你可以在自由的xib中引用myLabel。

Interface Builder will see the IBOutlets from the super classes too, so you'll be able to reference myLabel in your free xib.

确保MyPaidViewController是部分的付费和自由构建目标,但MyFreeViewController应该只是免费构建目标的一部分。

Make sure MyPaidViewController is part of the paid and the free build targets, but the MyFreeViewController should only be part of the free build target.

这篇关于如何在编译时使用不同的接口声明,而不会混淆Interface Builder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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