Pregunta

When I call my view controller, it comes up blank and does not seem to be correctly calling the layout in my NIB. I have at least 5 other classes that respect my NIB layout just fine.

I have a class chwFinishedViewController.h

On my storyboard I have a UIViewController that is assigned this class and given the storyboardID complete. See the below screenshot

issue screenshot

Here is 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

Here is how I call the controller. Everything before the controller call execute properly:

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

}
¿Fue útil?

Solución

Try this:

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

There is no relation between your xib and chwFinishedViewController constructor. You use just init which doesn't make anything. Here's apple doc.

EDIT

You use storyboard. So try this:

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

Otros consejos

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

Use this...

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

It should be:

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

Hope this helps.. :)

I had a similar issue, my solution was to remove an empty loadView method that had gotten left behind in the code for the viewcontroller class.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top