iOS – uinavigationController – Application tries to push a NIL view controller on the target, what do I miss?

I have a problem to get my navigation controller to work properly! If I click a cell of the table in RootViewController, it doesn’t seem to be the next ViewController.

The error message reads

“Application tried to push a nil view controller on target
.”

So I assigned something wrong, my guess, I might have missed the book I followed Important content.

So the problem appeared in my RootViewController.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:( NSIndexPath *)indexPath{

UINavigationController *navigationController= [[UINavigationController alloc]init];

switch ([indexPath row]) {

case 0:
[navigationController pushViewController:kundeViewCon animated:YES];
break;

case 1:
[navigationController pushViewController:kalenderViewCon animated:YES];
break;

case 2:
[navigationController pushViewController:wunschViewCon animated:YES];
break;
}
}

In my AppDelegate.m, I am doing the following to Set RootViewController as NavigationController:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

// Navigation Controller

RootViewController *rootViewController = [[RootViewController alloc]init];

navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController];

self.window.backgroundColor = [UIColor whiteColor] ;

[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}

So when I click on Cell, I get all the other ViewControllers I want to push. I just can’t see my fault or what I missed! ?

Maybe someone can help me and give me a hint! That’s great!

RootViewController already has its navigation controller – you created it in the app delegate. Choose It doesn’t make sense to create a new navigation controller for a cell. It should look more like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath: (NSIndexPath *)indexPath
{
switch ([indexPath row]) {
case 0:
[self.navigationController pushViewController:kundeViewCon animated:YES];
break ;
case 1:
[self.navigationController pushViewController:kalenderViewCon animated:YES];
break;
case 2:
[self.navigationController pushViewController:wunschViewCon animated: YES];
break;
}
}

In addition, just make sure that when calling -pushViewController:animated: the view controller (ie kundleViewCon, kalenderViewCon & wunschViewCon) is not Zero. They look like instance variables or attributes-just make sure to assign/start them early in the code, for example in -viewDidLoad.

I have a problem making me The navigation controller is operating normally! If I click a cell of the table in RootViewController, it doesn’t seem to be the next ViewController.

The error message reads

“Application tried to push a nil view controller on target
.”

So I assigned something wrong, my guess, I might have missed the book I followed Important content.

So the problem appeared in my RootViewController.m:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:( NSIndexPath *)indexPath{

UINavigationController *navigationController= [[UINavigationController alloc]init];

switch ([indexPath row]) {

case 0:
[navigationController pushViewController:kundeViewCon animated:YES];
break;

case 1:
[navigationController pushViewController:kalenderViewCon animated:YES];
break;

case 2:
[navigationController pushViewController:wunschViewCon animated:YES];
break;
}
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [ [UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.

// Navigation Controller

RootViewController *rootViewController = [[RootViewController alloc]init];

navigationController = [[UINavigationController alloc]initWithRootViewController:rootViewController];

self.window.backgroundColor = [UIColor whiteColor];

[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}

So When I click on Cell, I get all the other ViewControllers I want to push. I just can’t see my fault or what I missed! ?

Maybe someone can help me and give me a hint! That’s great!

RootViewController already has its navigation controller-you created it in the app delegate. It doesn’t make sense to create a new navigation controller when selecting a cell. It should look more like this:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch ([indexPath row]) {
case 0:
[self.navigationController pushViewController:kundeViewCon animated:YES];
break;
case 1:
[self.navigationController pushViewController:kalenderViewCon animated:YES];
break;
case 2:
[self.navigationController pushViewController:wunschViewCon animated:YES];
break;
}
}

Also, just make sure that when calling -pushViewController:animated: the view controllers (ie kundleViewCon, kalenderViewCon & wunschViewCon) are non-zero. They look like instance variables or properties – Just make sure to assign/start them early in the code, for example in -viewDidLoad.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3879 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.