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 6888853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:04:50+00:00 2026-05-27T06:04:50+00:00

I am trying to create a loop for (int i = 0; i <

  • 0

I am trying to create a loop

for (int i = 0; i < [tabNumbers count]; i++) 
{
    UIViewController *viewController;
    viewController = [[UIViewController alloc]  init];
    viewController.title = [tabNumbers objectAtIndex:i];
    viewController = [tabNumbers objectAtIndex:1];

    [viewControllersList addObject:viewController];
    [viewController release];
}

But the problem is that when I add view the array I get a bunch of view controllers with random names.

Rather than

UIViewController *viewController;

I am trying to do something like this

UIViewControlller *[NSString stringWithFormat:@"%@Controller",[tabNumbers objectAtIndex:i]]

But this doesn’t work

The reason being, is that once I have created the views in the loop, I am then looking to create a tab bar with each view as a tab and then each tab calls its own view controller

I can’t call the view controllers at the moment as I don’t know what the random number is that will be generated each time.

Thanks

Bob

Wow – two fantastic and prompt responses.

Unfortunately I am pretty new to Xcode and am slow on the uptake. I thought if I posted the full code it may help in trying to explain what I am trying to do.

So the idea is that the user can add, delete, move or rename tab bar items as they see fit.

The point that I have got to is that I can add the tab bar items, but am unable to get the tab bar items to create the new tables.

I know the code is correct to make the tab bar items – I can add as many tab bar items as I want.
I know that if I only draw one tab bar item that I can get the table to draw

But what I can’t do is get multiple tab bar items each to draw a table.

I thought that the best way was to dynamically name the view controller, which you guys have shown me is not possible.

So the next thought was to try and get it from the array, but given that the array will also change depending on what the user makes the tab bar name, I can’t see how this can work.

Any suggestions?

Please if possible, include some snippets of code – I am beginning to understand the code when I read it, but I don’t understand the definitions that explain (e.g. a tag for the view controller)

Thanks

Bob

- (void)showTabBar 
{
GuidelinesAppDelegate *AppDelegate = (GuidelinesAppDelegate *)[[UIApplication sharedApplication] delegate];
NSMutableArray *viewControllersList = [[NSMutableArray alloc] init];
NSMutableDictionary *tabItemsDict = [[NSMutableDictionary alloc] initWithObjects:tabNumbers forKeys:tabNumbers];
NSString *Path = [[NSBundle mainBundle] bundlePath];
NSString *DataPath = [Path stringByAppendingPathComponent:@"data.plist"];

UIViewController *viewController;
for (int i = 0; i < [tabNumbers count]; i++) 
{
    viewController = [[UIViewController alloc]  init];
    viewController.title = [tabNumbers objectAtIndex:i];
    [viewControllersList addObject:viewController];
    [viewController release];
}

AppDelegate.tabItemsDict = tabItemsDict;
[self.tabBarController setViewControllers:viewControllersList animated:YES];

for (NSString *s in viewControllersList)
{
    RootViewController *rootViewController = [[RootViewController alloc] initWithStyle:UITableViewStylePlain];        
    NSMutableDictionary *tabTableStructureDict = [[NSMutableDictionary alloc] initWithContentsOfFile:DataPath];
    AppDelegate.tabTableStructureDict = tabTableStructureDict;

    UINavigationController *bNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
    self.navigationController = bNavigationController;
    [self.view addSubview:[navigationController view]];

    [bNavigationController release];
    [rootViewController release];
}

}

  • 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-27T06:04:50+00:00Added an answer on May 27, 2026 at 6:04 am

    A couple ways that might solve this for you…

    First off, forget the idea of giving the view controllers a strong reference with a random name, this is not necessary.

    UIView has a tag property, this is meant for identifying views. Assign the tag property to the view as you create it and add it to the array. You can then obtain that view again knowing the tag number by filtering on the array or iterating through it.

    Another way is to use a dictionary where your key is the view’s number and the value is the view itself. So this way you can obtain the view by fetching the value using the key.

    Another, arrays are ordered, as you add items to them the order remains the same unless you explicitly modify it, adding an item to a mutable array will place that item at the end, so inherently you know which view is which since you know when you added them to the array.

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

Sidebar

Related Questions

I am running a loop, and I am trying to create a variable each
Im trying to create a simple loop that creates 50 buttons, adds them to
I'm trying to create a parallel foreach loop to processes a fasta file. I've
I'm trying to create a loop to avoid copy pasting these lines 30 times.
Ok, so I'm trying to create a program using a while loop to find
when trying to use a loop to create a jagged array, but what happens
I'm trying to create a game loop using this tutorial . I have tried
I am trying to create dynamic checkboxes in a for loop. But I am
I am trying to create a function that will take an int and separately
having a small problem. I'm trying to create a loop that will create an

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.