类不显示来自NIB的视图

时间:2014-02-19 04:45:11

标签: ios xcode uiviewcontroller storyboard nib

当我调用我的视图控制器时,它显示为空白,似乎没有正确调用我的NIB中的布局。我至少有5个其他类可以很好地尊重我的NIB布局。

我有一个班级chwFinishedViewController.h

在我的故事板上,我有UIViewController分配了这个类,并给出了storyboardID complete。见下面的截图

issue screenshot

以下是chwFinishedViewController.m

#import "chwFinishedViewController.h"

@interface chwFinishedViewController ()

@end

@implementation chwFinishedViewController

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

以下是我如何调用控制器。控制器调用之前的所有内容都正确执行:

 if (!error) {
chwFinishedViewController *complete = [[chwFinishedViewController alloc] init];
[self.navigationController pushViewController:complete animated:YES];

}

5 个答案:

答案 0 :(得分:4)

试试这个:

chwFinishedViewController *complete = [[chwFinishedViewController alloc] initWithNibName:@"complete" bundle:nil];

你的xib和chwFinishedViewController构造函数之间没有关系。你只使用init而不做任何事情。 Here's apple doc

修改

您使用故事板。所以试试这个:

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
chwFinishedViewController* complete = [storyboard instantiateViewControllerWithIdentifier:@"complete"];

答案 1 :(得分:2)

 you have just init the controller..
use initWithNibName instead of only init

答案 2 :(得分:0)

使用此...

chwFinishedViewController *complete = [[chwFinishedViewController alloc] initWithNibName:@"complete" bundle:nil]; 

答案 3 :(得分:0)

应该是:

chwFinishedViewController *complete = [[chwFinishedViewController alloc] initWithNibName:@"complete" bundle:nil]; 

希望这会有所帮助.. :)

答案 4 :(得分:0)

我有一个类似的问题,我的解决方案是删除一个空的loadView方法,该方法在viewcontroller类的代码中留下了。