2

我正在 iOS 4.2 及更高版本中创建一个通用应用程序。

我有一个叫DataInputViewController_iPhone.xib. 在出现的第一个视图控制器上,我有一个应该启动类的按钮DataInputViewController。它可以,但它不显示 XIB 文件的内容。它只是显示一个黑屏。

任何想法为什么会发生这种情况?

我有这段代码调用新的视图控制器:

-(IBAction)clickedButton:(id)sender {
    if((UIButton *)sender == (UIButton *)startButton){
        NSString *nibName;
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
            nibName = @"DataInputViewController_iPhone";
        } else {
            nibName = @"DataInputViewController_iPad";
        }

        DataInputViewController *nextVC = [[DataInputViewController alloc] initWithNibName:nibName bundle:nil];
        [self.navigationController pushViewController:nextVC animated:YES];
    }
    else if((UIButton *)sender == (UIButton *)otherButton){
        NSLog(@"clicked the other button");
    }
}

NSLogging 在这个方法和init新视图控制器的方法中告诉我nibNameOrNil变量被正确拉出。

这就是(标准)init 方法的样子DataInputViewController.m

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

任何想法为什么会发生这种情况?或者如何修复?

谢谢 :)

4

9 回答 9

2

您不必手动设置笔尖名称。只需将它们命名为DataInputViewController~iphone.xibDataInputViewController~ipad.xib然后调用[[DataInputViewController alloc] init]

有关更多信息,请参阅iOS 支持设备特定资源

于 2012-04-25T13:33:24.607 回答
2

我有同样的问题。只需清理您的项目,关闭 XCode,重新启动您的 Mac 并再次打开项目。并且不要忘记之前在模拟器或设备上删除应用程序。

于 2013-04-10T12:50:21.390 回答
1

我遇到了同样的问题,我需要为实用程序视图控制器加载 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

我希望这可以帮助其他遇到这个耗时且非常令人沮丧的问题的人。

于 2013-08-08T16:08:37.643 回答
1

我发现解决此问题的唯一方法是删除笔尖和类,然后重新创建它们。不是特别优雅,但它有效......

于 2012-04-27T08:44:02.413 回答
0

这可能会对您有所帮助:删除模拟器或设备上的应用程序并再次运行。我发现如果我过多地使用笔尖,尤其是在名称或本地化方面,似乎一切正常(我没有错误),但 Xcode 实际上忽略了这些更改。

所以执行清洁(Product->Clean),从模拟器或设备中删除,再次运行。

于 2012-04-25T15:31:21.867 回答
0

我发现不将出口从文件所有者拖到您的自定义子类 UITableViewCell.h 或 .m 文件也会导致变黑。确保将插座拖到与 UITableViewCell 的子类关联的两个文件之一。

于 2013-07-04T03:24:59.947 回答
0

您必须确保在 DataInputViewController.m 中实现 loadView 方法,并在方法内添加 [super loadView] 行,如下所示:


- (void)loadView {
    [super loadView];
}
于 2013-05-18T05:35:38.643 回答
0

就我而言,我从同事那里收到了 xib 文件。加载良好的xib,但没有显示。因为选中了隐藏复选框,所以我一天都花光了

检查xib中的隐藏复选框。

于 2016-10-27T08:41:49.500 回答
0

简单修复!!导航到版本编辑器并返回标准编辑器为我解决了这个问题

于 2017-09-01T20:21:00.127 回答