Error with top view controller

I have one difficulty with the root view controller.

enter image description here Picture(1)

Within the below code and the picture 1, everything work fine. But within picture 2 enter image description here Picture (2), I got an error said that

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BannerViewController topViewController]: unrecognized selector sent to instance 0x7feb9b64dbc0'

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UINavigationController *navController = tabBarController.viewControllers[0];

    ItemListTableViewController *itemList = (ItemListTableViewController *)navController.topViewController;
    itemList.managedObjectContext = self.managedObjectContext;

    return YES;
}

So please help me how to insert a view controller in front of the navigation controller?


ANSWERS:


You can get a reference to the navigation controller through the childViewControllers property of the container VC:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
    UIViewController *containerVC = tabBarController.viewControllers[0];
    UIView *containerVCview = containerVC.view;
    UINavigationController *navController = containerVC.childViewControllers[0];

    ItemListTableViewController *itemList = (ItemListTableViewController *)navController.topViewController;
    itemList.managedObjectContext = self.managedObjectContext;

    return YES;
}


 MORE:


 ? iOS Change rootViewController Dynamically
 ? Can't change rootViewController in Appdelegate?
 ? self.window.rootViewController.presentedViewController returning nil
 ? Xamarin Studio - Ctrl + Drag to assign Root View Controller
 ? Xamarin Studio - Ctrl + Drag to assign Root View Controller
 ? Xamarin Studio - Ctrl + Drag to assign Root View Controller
 ? Why can't I create a segue using the iOS Designer? - Xamarin Studio
 ? Strange error about type defined multiple times with PCL
 ? Error since migrating to Unified version in Xamarin.IOS
 ? tableView Scrolling issue Xamarin.ios