1

Other xib's auto-load fine, but not this one.

When I push this viewcontroller, initWithNibName, loadView, viewDidLoad, and viewWillAppear are called fine, but the view (and all self.xxx objects in @interface) are nil in all these methods, and I am left with an empty window under the navigationbar.

SettingsMain *newVC=[[SettingsMain alloc] initWithNibName:@"SettingsMain" bundle:nil];
[self.navigationController pushViewController:newVC animated:YES];

I was wondering if I can force setting self.view to what's in the .xib, in loadView or initWithNibName, so that all the outlets etc are initalized.

The viewcontroller has the standard code,

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

    }
    return self;
}

The problem is that when viewDidLoad is fired, self.view is nil.

Henrik Erlandsson
  • 3,797
  • 5
  • 43
  • 63
  • 2
    did you set the outlet for the view in your nib file? Because the loadView method is only called if the view property is "nil" – CarlJ Aug 15 '12 at 13:46
  • 1
    It could be that you forgot to set the outlet to view in SettingsMain xib file. – Sierra Alpha Aug 15 '12 at 13:48
  • No, it's connected. What could set it to nil, or what is needed to "read the connection and set .view"? I'm guessing, -init or -initWithFrame:. But the point of a xib is to not have to write those. – Henrik Erlandsson Aug 15 '12 at 14:21
  • Is the file's owner set properly? And the ViewControllerClass? – Hermann Klecker Aug 15 '12 at 14:46
  • What does the debug window tell you when the initWithNibName method is called? Sometimes you get some useful hint there. – Hermann Klecker Aug 15 '12 at 14:47
  • can you describe the code of UIViewController lifecycle methods you override in your controller and how – atastrophic Aug 15 '12 at 16:46
  • @tGilani, -loadView contains no code, -viewDidLoad only sets self.title, and -viewWillAppear populates an array and tries to set some properties for the tableview in .xib. – Henrik Erlandsson Aug 16 '12 at 06:12
  • @HermannKlecker, yes and yes. To me it's very strange that the Navbar animated and shows the back arrow button, but shows the empty view. – Henrik Erlandsson Aug 16 '12 at 06:15
  • try removing loadView implementation completely or call [super loadView]; and see if it works – atastrophic Aug 16 '12 at 06:42

0 Answers0