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

  • Home
  • SEARCH
  • 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 595669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T16:05:16+00:00 2026-05-13T16:05:16+00:00

I am creating my Nav and TabBar in code at launch via: IN :

  • 0

I am creating my Nav and TabBar in code at launch via:
IN : myAppDelegate.m

- (void)applicationDidFinishLaunching:(UIApplication *)application { 
    // set up a local nav controller which we will reuse for each view controller
    UINavigationController *localNavigationController;

    // create tab bar controller and array to hold the view controllers
    tabBarController = [[UITabBarController alloc] init];
    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:4];

    // setup the first view controller (Root view controller)
    RootViewController *myViewController;
    myViewController = [[RootViewController alloc] initWithTabBar];

    // create the nav controller and add the root view controller as its first view
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];

    // add the new nav controller (with the root view controller inside it)
    // to the array of controllers
    [localControllersArray addObject:localNavigationController];

    // release since we are done with this for now
    [localNavigationController release];
    [myViewController release];

    // setup the first view controller just like the first 
    ResortsListViewController *resortsListViewController;
    resortsListViewController = [[ResortsListViewController alloc] initWithNibName:@"ResortsListView" bundle:nil];
    resortsListViewController.title = @"Category1";
    resortsListViewController.tabBarItem.image = [UIImage imageNamed:@"image1.png"];
    resortsListViewController.navigationItem.title=@"Category1";
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:resortsListViewController];
    [localControllersArray addObject:localNavigationController]; 
    [localNavigationController release];

    // setup the second view controller just like the first 
    ResortsListViewController *resortsListViewController;
    resortsListViewController = [[ResortsListViewController alloc] initWithNibName:@"ResortsListView" bundle:nil];
    resortsListViewController.title = @"Category2";
    resortsListViewController.tabBarItem.image = [UIImage imageNamed:@"image2.png"];
    resortsListViewController.navigationItem.title=@"Category2";
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:resortsListViewController];
    [localControllersArray addObject:localNavigationController]; 
    [localNavigationController release];

    // setup the third view controller just like the first 
    ResortsListViewController *resortsListViewController;
    resortsListViewController = [[ResortsListViewController alloc] initWithNibName:@"ResortsListView" bundle:nil];
    resortsListViewController.title = @"Category3";
    resortsListViewController.tabBarItem.image = [UIImage imageNamed:@"image3.png"];
    resortsListViewController.navigationItem.title=@"Category3";
    localNavigationController = [[UINavigationController alloc] initWithRootViewController:resortsListViewController];
    [localControllersArray addObject:localNavigationController]; 
    [localNavigationController release];

    [resortsListViewController release];

    // load up our tab bar controller with the view controllers
    tabBarController.viewControllers = localControllersArray;

    // release the array because the tab bar controller now has it
    [localControllersArray release];

    // add the tabBarController as a subview in the window
    [window addSubview:tabBarController.view];

    // need this last line to display the window (and tab bar controller)
    [window makeKeyAndVisible];


}

As you see, I am re-using ResortsListViewController for different category displays (resorts with Beaches, resorts with Pools, resorts with espresso bars) … now, without harassing me (grin) about the silliness of my categories (cos this is a test app) I need need to do several things:

  1. I need to be able to know which tab click caused the ResortsListViewController to be displayed. I was hoping to use TAG but “initWithRootViewController” does not have the “tag” control. So, if i use an imagefilename that is the category name, I can use that filename to distinguish categories…or even navigationItem name. I need to know if there is a way for ResortsListViewController to know which tabbar item click caused it’s display. I thought to look for a “action” that I could assign to the tabbar item, but that is not the way tabbarcontroller works.

  2. When clicking from one tab to another, the view does indeed change, the title of ResortsListViewController changes, etc…but the TABLEVIEW it holds does not clear and display any new data. Searching the web I have found a possible solution:

http://discussions.apple.com/thread.jspa?threadID=1529769&tstart=0

basically saying:

In order for UINavigationControllers
to send
“viewWill/Did/Appear/Disappear”
messages, it needs to have received
“viewWill/Did/Appear/Disappear” from
its container.

What is the container for my UINavigationControllers in this situation? myAppDelegate is defined in the .h file as:

NSObject <UIApplicationDelegate, CLLocationManagerDelegate>

and does not have a:

- (void)viewWillAppear:(BOOL)animated {
}

section. When I add one it says “NSObject may not respond to -viewWillAppear” in the debugger.

Any help out there?

  • 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-13T16:05:16+00:00Added an answer on May 13, 2026 at 4:05 pm

    Okay, here goes: This is the correct answer to the question, however, it did not end up being this hard. All I had to do was the following:

    Create a property in ResortViewController of type int with variable name whichChoice (for instance). Then address it in the setup of the TabBarController a la:

    // setup the first view controller just like the first 
        ResortsListViewController *resortsListViewController;
        resortsListViewController = [[ResortsListViewController alloc]     initWithNibName:@"ResortsListView" bundle:nil];
        //  START HERE IS THE CHANGE
        resortsListViewController.whichChoice = 1;
        //  END HERE IS THE CHANGE
        resortsListViewController.title = @"Category1";
        resortsListViewController.tabBarItem.image = [UIImage imageNamed:@"image1.png"];
        resortsListViewController.navigationItem.title=@"Category1";
        localNavigationController = [[UINavigationController alloc] initWithRootViewController:resortsListViewController];
        [localControllersArray addObject:localNavigationController]; 
        [localNavigationController release];
    

    To find out which tab was clicked when my resortsListViewController takes over, I simply query the class variable: whichChoice to get the answer.

    Things like this are so simple you skip over them. I thought you had to pass the variable in an action and specify where it would go with the target like you do in other objects — but when you set things up ahead of time you do not have to do that. Now, having said that, dynamically setting “whichChoice” is not so easy without a lot more thought…but setting it to a variable KNOWN at setup is fine.

    For answer #2, I simply put a variable style of IBOutlet in my class, hooked it up to the table, and then followed your instructions, because without the variable in the IBOutlet and hooking it up to the table, there is no reference to the table view. For some reason hooking up the table simply to the VIEW “Referencing Outlet” and calling [self.tableview reloadData] did not do the job.

    But for the most part, your answers were right and led me in the right direction. As an aside, I really hate that you have to right-click and drag from here-to-there in IB if you have an IB element you built. You should be able to hook it up in code using it’s ObjectId (or something). That would be more in line with programmers. I know IB is made to allow programming to be easier for designers, but gee wilikers..it is hard to wrap my mind around! I end up dropping IB and creating elements in code most of time time…which I do not know if is as fast to execute. I tend to think not…but have no proof to the contrary.

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

Sidebar

Ask A Question

Stats

  • Questions 299k
  • Answers 299k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer There may be other ways, but what follows is a… May 13, 2026 at 7:43 pm
  • Editorial Team
    Editorial Team added an answer Wrap your table name in ` (tick marks) so that… May 13, 2026 at 7:43 pm
  • Editorial Team
    Editorial Team added an answer Are you running a firewall? Maybe you could use the… May 13, 2026 at 7:43 pm

Related Questions

I am creating a web site for my church. Because they know of no
I am currently creating a type of classifieds website, and when the user enters
I have created a flexible navigation bar in my app that will show custom
In an ASP.NET 2.0 website, I have a string representing some well-formed XML. I
I am creating my textbox with these options. I can Copy / Cut /

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.