0

Here's my MainWindow.xib. It contains a tab bar, the entries of which contain a UINavigationController each. Both CalendarViewController and SettingsViewController have no associated nibs.

From inside CalendarViewController, I can access self.navigationController just fine, but not from SettingsViewController. There, self.navigationController always returns nil.

What could I have forgotten? The view controller itself works just fine, btw.

winsmith
  • 20,791
  • 9
  • 39
  • 49
  • Nothing wrong there, but somehow you are pushing SettingsViewController from a view controller which has no navigationController. Maybe you should post the initialization of the tab bar controller in didFinishLaunchingWithOptions, or how you are reaching the SettingsViewController. – Jano Nov 14 '11 at 11:50
  • Ha! I had a custom initWithCoder method in SettingsViewController that somehow prevented the correct initialization. Do you want to post your comment as an answer so you can get honor, glory and SO-points? – winsmith Nov 14 '11 at 12:01
  • Compare the comment on: http://stackoverflow.com/questions/1006663/how-can-i-set-a-uitableview-to-grouped-style/6163249#6163249 – winsmith Nov 14 '11 at 12:02
  • You can accept your own answer, mine wasn't complete. – Jano Nov 14 '11 at 15:01

1 Answers1

2

Found the solution (Thanks to Jano): My initWithCoder: method looked like this:

- (id) initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithStyle:UITableViewStyleGrouped];
    return self;
}

This didn't read the values represented in aDecoder and thus didn't initialize the navigationControllerproperty. I replaced it with this bit of code:

- (id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    return self;
}
winsmith
  • 20,791
  • 9
  • 39
  • 49