Note that there are some explanatory texts on larger screens.

plurals
  1. POself.NavigationController is nil even if called with initWithRootViewController
    primarykey
    data
    text
    <p>I can't figure out what am I doing wrong here, I have there are other posts about it but they seem related to a more articulate case, in my situation, everything seems very simple, but still it doesn't work.</p> <p>In my AppDelegate.m</p> <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { MyViewController *vc = [[MyViewController alloc] init]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:vc]; // Instantiate the window self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; self.window.rootViewController = navigationController; // Show the window [self.window makeKeyAndVisible]; return YES; } </code></pre> <p>In MyViewController.m (there is no xib file)</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; NSLog(@"self.navigationController %@", self.navigationController); } </code></pre> <p>The result of this is:</p> <pre><code>2012-02-26 22:41:19.366 Test [4488:15203] self.navigationController (null) </code></pre> <h1>EDIT</h1> <p>So, I almost figured out but I haven't understood the reason.</p> <p>First of all, to better specify, my view controllers were UITableViewControllers, and the problem apparently relies on the initWithStyle method customization I made:</p> <pre><code>- (id)init { self = [self initWithStyle:UITableViewStyleGrouped]; return self; } - (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { [[self tableView] setBackgroundColor:kTableViewBackgroundColor]; [[self tableView] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; } return self; } </code></pre> <p>If I comment out the two rows inside the if, i.e. if I do:</p> <pre><code>- (id)initWithStyle:(UITableViewStyle)style { self = [super initWithStyle:style]; if (self) { //[[self tableView] setBackgroundColor:kTableViewBackgroundColor]; //[[self tableView] setSeparatorStyle:UITableViewCellSeparatorStyleSingleLine]; } return self; } </code></pre> <p>the self.NavigationController gets instantiated properly, otherwise it doesn't. Can someone explain me why this happens?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload