Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7587059
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:34:47+00:00 2026-05-30T19:34:47+00:00

New to iOS development, I’ve been following the tutorials on developer.apple.com, and am now

  • 0

New to iOS development, I’ve been following the tutorials on developer.apple.com, and am now adding functionality to those examples to further my knowledge.

The “second ios app” tutorial gives you a navigation controller based app. Extending this app, I want to have a tab bar controller as the first view controller.

So I now have the following setup:

Storyboard

All good. But there is code in the BirdsAppDelegate (a UIApplicationDelegate) which was relying on the navigation controller being the root view controller, so it can create and assign the “datacontroller” object.

This is the original code (before I added the tab bar controller):

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

    UINavigationController *navigationController = (UINavigationController *)self.window.rootViewController;
    BirdsMasterViewController *firstViewController = (BirdsMasterViewController *)[[navigationController viewControllers] objectAtIndex:0];

    BirdSightingDataController *aDataController = [[BirdSightingDataController alloc] init];
    firstViewController.dataController = aDataController;
    return YES;
}

Now this code fails because it assumes the root view controller is the navigation controller.

I have updated the code so that it works – but in my opinion it is ugly, and would have to be changed every time I make a change to the view controller hierarchy:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions
{
    // Override point for customization after application launch.

    UITabBarController *tabBarController =  (UITabBarController *)self.window.rootViewController;

    UINavigationController *navigationController = (UINavigationController *)    [[tabBarController viewControllers] objectAtIndex:0];

    BirdsMasterViewController *firstViewController = (BirdsMasterViewController*) [[navigationController viewControllers] objectAtIndex:0];

    BirdSightingDataController *aDataController = [[BirdSightingDataController alloc] init];

    firstViewController.dataController = aDataController;

    return YES;
}

So my question is: What is the better way to do what I am doing in the code above, so that any changes to the hierarchy will not break the code?

How do I programmatically access the view controller I am after in the application delegate, so that I can create and assign it’s BirdSightingDataController object?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T19:34:48+00:00Added an answer on May 30, 2026 at 7:34 pm

    You can loop the [navigationController viewControllers] array looking for an instance of BirdsMasterViewController… Using [obj isKindOfClass:[BirdsMasterViewController class]].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new in ios development .Now i am trying to develop an ipad
I am new in ios development.Now,i am developing an Ipad application using ios 4.2
I am new in ios development, Now i am doing some animation on my
I am new in iOS development. Now I want to give an external property(similar
I'm new to Cocca and IOS development and find myself in the following situation.
I am new in IOS development .Now i implement a UINavigationController to a UIViewController,
I am new to iOS development. Now I am implementing an UIPanGestureRecognizer model application.
I am new in ios development.Now , i am trying to implement an application
I'm new with iOS development, but I'm familiar with the memory management basics in
I am new to iOS development and am trying to figure out how it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.