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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T11:20:53+00:00 2026-06-06T11:20:53+00:00

I want to be able to dynamically create ViewControllers based on a JSON file.

  • 0

I want to be able to dynamically create ViewControllers based on a JSON file. What I mean is, there will be a json that will dictate how many ViewControllers the user needs. I.e say I have a json file that lays out 5 ViewControllers, I want to be able to dynamically create these ViewControllers and be able to transition between them.

So what I am going to have is JSON file, that sets out the ViewControllers, say 3 for this example. This JSON file has info on the text, buttons etc and how to navigate between them.

So I want to be able to loop through this JSON, and create the necessary view controllers and add the required text, buttons etc. The JSON will also dictate how the view controllers link up together.

I know how to create one VC and add info like this (This is just quick example, just created vc and added label.

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor whiteColor];

    UILabel *testLabel =[[UILabel alloc] initWithFrame:CGRectMake(220, 50, 130, 80)];
    testLabel.backgroundColor = [UIColor clearColor];
    testLabel.textColor = [UIColor blackColor];
    testLabel.text = @"Hello";;

    [vc.view addSubview:testLabel ];
    [self.navigationController pushViewController:vc animated:YES];

I don’t know how to create several differently named ViewControllers in a loop using JSON. Anyone have any ideas on how to do this? Or is something like this even possible?

Any assistance would be greatly appreciated.

EDIT:

Very basic example of what JSON will look like

{
   "ViewControllers":[
      {
         "name":"FirstVC",
         "id":1
      },
      {
         "name":"SecondVC",
         "id":2
      },
      {
         "name":"ThirdVC",
         "id":3
      }
   ]
}

So first VC links to secondVC and second to thirdVC

  • 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-06-06T11:20:55+00:00Added an answer on June 6, 2026 at 11:20 am

    Just create an array and hold them there. Something like this:

    NSMutableArray *viewControllers = [[NSMutableArray alloc] initWithCapacity:0];
    
    // ...
    // Inside a loop
    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor whiteColor];
    
    UILabel *testLabel =[[UILabel alloc] initWithFrame:CGRectMake(220, 50, 130, 80)];
    testLabel.backgroundColor = [UIColor clearColor];
    testLabel.textColor = [UIColor blackColor];
    testLabel.text = @"Hello";
    
    [viewControllers addObject:vc];
    // Release vc and label if you're not using ARC
    

    Now, if you want to name your controllers, one idea would be to create a subclass of UIViewController and add a name (or something like that) property. Then you just set this property also inside your loop and you can refer/filter based on that property.

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

Sidebar

Related Questions

I want to create div dynamically based on some calculations.I am able build div's
I want to be able to create as many records as a user wants
Basically i want to be able to dynamically create a temp table based off
I just want to add ContextMenu for several objects that I create dynamically, but
I'm trying to create a list application that will let a user inputs an
I want to be able to take an image that i have already captured
I want to be able to create a Pandas DataFrame with MultiIndexes for the
So I have a function and I want to be able to create and
I want to be able to create and unknown number of objects. I'm not
I'm having an issue with my android application. I want to dynamically create 4

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.