How to use different interface declarations at compile time without confusing Interface Builder

前端 未结 1 386
失恋的感觉
失恋的感觉 2021-01-23 08:48

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

相关标签:
1条回答
  • 2021-01-23 09:03

    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:

    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> {
    

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

    @interface MyFreeViewController : MyPaidViewController <ADBannerViewDelegate> {
    

    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 will see the IBOutlets from the super classes too, so you'll be able to reference myLabel in your free xib.

    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.

    0 讨论(0)
提交回复
热议问题