我遇到了同样的问题,我需要为实用程序视图控制器加载 iPad 或 iPhone .xib 文件。它是一个表单,因此它有很多作为 IBOutlets 链接的 UILabel 和 UITextField 元素。我会构建整个布局,链接所有元素,它工作正常,直到我构建并运行它。我什至接受了发布在该线程上的建议并重新创建了 .xib 和类文件(大量链接 IBOutlets),但没有成功。
问题是这样的。在类的实现中不能@synthesized 根视图。一旦我合成了基础视图,一切都变黑了。通过简单地删除“@synthesize 视图;” 行,一切都像一个魅力。当我展示我的视图控制器时,一切都再次出现了。
这是包含所有 IBOutlets 的类的头文件:
#import <UIKit/UIKit.h>
@interface SignUpFormViewController : UIViewController <UITextFieldDelegate, NSXMLParserDelegate>
@property (strong, nonatomic) IBOutlet UIView *rootView;
@property (weak, nonatomic) IBOutlet UILabel *signUpFormLabel;
@property (weak, nonatomic) IBOutlet UIButton *infoButton;
@property (weak, nonatomic) IBOutlet UILabel *enterEmailLabel;
@property (weak, nonatomic) IBOutlet UITextField *enterEmailTextField;
@property (weak, nonatomic) IBOutlet UILabel *enterPasswordLabel;
@property (weak, nonatomic) IBOutlet UITextField *enterPasswordTextField;
@property (weak, nonatomic) IBOutlet UILabel *reEnterPasswordLabel;
@property (weak, nonatomic) IBOutlet UITextField *reEnterPasswordTextField;
@property (weak, nonatomic) IBOutlet UILabel *enterFirstNameLabel;
@property (weak, nonatomic) IBOutlet UITextField *enterFirstNameTextField;
@property (weak, nonatomic) IBOutlet UILabel *enterLastNameLabel;
@property (weak, nonatomic) IBOutlet UITextField *enterLastNameTextField;
@property (weak, nonatomic) IBOutlet UILabel *enterPhoneNumberLabel;
@property (weak, nonatomic) IBOutlet UITextField *enterPhoneNumberTextField;
@property (weak, nonatomic) IBOutlet UILabel *enterStreetAddressLabel;
@property (weak, nonatomic) IBOutlet UITextField *enterStreetAddressTextField;
@property (weak, nonatomic) IBOutlet UILabel *enterStreetAddress2Label;
@property (weak, nonatomic) IBOutlet UITextField *enterStreetAddress2TextField;
@property (weak, nonatomic) IBOutlet UILabel *enterCityLabel;
@property (weak, nonatomic) IBOutlet UITextField *enterCityTextField;
@property (weak, nonatomic) IBOutlet UILabel *enterStateLabel;
@property (weak, nonatomic) IBOutlet UITextField *enterStateTextField;
@property (weak, nonatomic) IBOutlet UILabel *enterZipLabel;
@property (weak, nonatomic) IBOutlet UITextField *enterZipTextField;
@property (weak, nonatomic) IBOutlet UIButton *backButton;
@property (weak, nonatomic) IBOutlet UIButton *signUpNowButton;
- (IBAction)infoButtonPressed:(id)sender;
- (IBAction)backButtonPressed:(id)sender;
- (IBAction)signUpNowButtonPressed:(id)sender;
@end
这是正在合成根视图的实现文件:
#import "SignUpFormViewController.h"
@implementation SignUpFormViewController
@synthesize rootView,signUpFormLabel,infoButton,enterEmailLabel,enterEmailTextField,enterPasswordLabel,enterPasswordTextField,reEnterPasswordLabel,reEnterPasswordTextField,enterFirstNameLabel,enterFirstNameTextField,enterLastNameLabel,enterLastNameTextField,enterPhoneNumberLabel,enterPhoneNumberTextField,enterStreetAddressLabel,enterStreetAddressTextField,enterStreetAddress2Label,enterStreetAddress2TextField,enterCityLabel,enterCityTextField,enterStateLabel,enterStateTextField,enterZipLabel,enterZipTextField,backButton,signUpNowButton,btnDone,btnPrev,btnNext,inputAccView,activeTextField,currentString;
只需从正在合成的属性列表中删除“rootView”,这应该可以解决问题。比删除 iPad 和 iPhone 布局的 .xib 文件并重新创建它们要容易得多。
仅供参考,我正在使用目标 SDK = 6.1 的 xCode 4.6.3
我希望这可以帮助其他遇到这个耗时且非常令人沮丧的问题的人。