Thomas Clayson Thomas Clayson - 1 month ago 11
iOS Question

XIB doesn't load... just shows a black screen

I'm creating a universal application in iOS 4.2 and above.

I have a nib called

DataInputViewController_iPhone.xib
. On the first view controller which comes up I have a button which should launch the class
DataInputViewController
. It does it, but it doesn't show the contents of the XIB file. It just shows a black screen.

Any ideas why this happens?

I have this code which calls the new view controller:

-(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 in this method and in the
init
method of the new view controller tells me that the
nibNameOrNil
variable is pulled through correctly.

This is what the (standard) init method looks like in
DataInputViewController.m
:

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


Any ideas why this is happening? Or how to fix?

Thanks :)

Answer

The only way I have found to fix this is to delete the nibs and class and then recreate them. Not particularly elegant, but it works ...