【问题标题】:IBOutlet is not recognized by Interface Builder when conditioning compiling in Interface declaration在接口声明中进行条件编译时,接口生成器无法识别 IBOutlet
【发布时间】:2011-07-02 01:19:32
【问题描述】:

如果我在作为 xib 文件所有者的头文件中添加此条件编译标志,则 xib 文件无法读取 IBOutlet 并显示为丢失。并给出警告。

在运行时它工作正常。有人遇到过同样的问题吗?

/* MFMessageComposeViewControllerDelegate is available in iOS 4.0 and later. */



#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000

   @interface SendMoneyResponseVC : UITableViewController 
    <UINavigationControllerDelegate, MFMessageComposeViewControllerDelegate,    
    MFMailComposeViewControllerDelegate, UIActionSheetDelegate> 

   #else

   @interface SendMoneyResponseVC : UITableViewController 
    <UINavigationControllerDelegate, 
    MFMailComposeViewControllerDelegate, UIActionSheetDelegate> 

    #endif 

{
    IBOutlet UITableView *sendMoneyTableVC;

    IBOutlet UITableViewCell *refNumRemittanceCell;
    IBOutlet UILabel *refNumLabel, *refNumValueLabel, *refNumInfoLabel;

    IBOutlet UITableViewCell *refNumDomesticCell;
    IBOutlet UILabel *domesticInfoLabel, *feeAndReferenceLabel;

    IBOutlet UITableViewCell *shareRefNumCell;
    IBOutlet UIButton *shareRefNumButton;

    NSString *referenceNumber, *recipient, *currency, *mtoName;
    float amount, fee;
    int sendMoneyType;

    UIAlertView *smsAlertView;
}

@property (nonatomic, retain) UITableView *sendMoneyTableVC;

@property (nonatomic, retain) UITableViewCell *refNumRemittanceCell;
@property (nonatomic, retain) UILabel *refNumLabel, *refNumValueLabel, *refNumInfoLabel;

@property (nonatomic, retain) UITableViewCell *refNumDomesticCell;
@property (nonatomic, retain) UILabel *domesticInfoLabel, *feeAndReferenceLabel;

@property (nonatomic, retain) UITableViewCell *shareRefNumCell;
@property (nonatomic, retain) UIButton *shareRefNumButton;

@property (nonatomic, retain) NSString *referenceNumber, *recipient, *currency, *mtoName;
@property float amount, fee;
@property int sendMoneyType;

- (IBAction) didPressShareButton;

@end

【问题讨论】:

    标签: iphone xib conditional-compilation


    【解决方案1】:

    这样做的原因是什么?除非您想使用过时的 SDK 进行编译,否则您应该摆脱它。

    Interface Builder 不会预处理您的文件,因此它会看到两个 @interface 和一个 @end。
    并且接口生成器无法解析这样的东西。

    【讨论】:

    • 没错。我已经用 XCode 3.1.2 测试了我的代码。要使用旧 SDK 进行编译,我需要添加这个预处理器。我知道最新的 xcode 不需要它。但是寻找任何解决方法来避免 IB 警告。
    【解决方案2】:

    您是否尝试过以与编译器等效的方式重构代码,但不太可能混淆 Interface Builder?像这样的:

    @interface SendMoneyResponseVC : UITableViewController 
        <UINavigationControllerDelegate, 
    #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
        MFMessageComposeViewControllerDelegate,    
    #endif 
        MFMailComposeViewControllerDelegate, 
        UIActionSheetDelegate> 
    { ... }
    @end
    

    这样就只有一对@interface/@end

    【讨论】:

      猜你喜欢
      • 2018-09-05
      • 2021-03-24
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-05
      相关资源
      最近更新 更多