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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T05:49:29+00:00 2026-06-05T05:49:29+00:00

I have a UITableViewController that uses an array with values for every entry in

  • 0

I have a UITableViewController that uses an array with values for every entry in the rows.
I want to set the values of that array by iterating over values read from a JSON file.

This is the new method I have created to read that data into an array and return it to my view controller. I don’t know where to return the array, or how to really set it.

+(NSArray *)setDataToJson{
NSDictionary *infomation = [NSDictionary dictionaryWithContentsOfJSONString:@"Test.json"];
NSArray *test = [infomation valueForKey:@"Animals"];
for (int i = 0; i < test.count; i++) {
    NSDictionary *info = [test objectAtIndex:i];
    NSArray *array = [[NSArray alloc]initWithObjects:[Animal animalObj:[info valueForKey:@"AnimalName"] 
location:[info valueForKey:@"ScientificName"] description:[info valueForKey:@"FirstDesc"] image:[UIImage imageNamed:@"cat.png"]], nil];
        return array;

I know that my animalObj function worked when the data was local strings(@”Cat”) and my dictionaryWithContentsOfJSONString works because I have tested, but I haven’t used this function to set data to an array, only to UILabels, so this is where I am confused, on how to set this data into an array. But still use the For loop.

  • 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-05T05:49:30+00:00Added an answer on June 5, 2026 at 5:49 am

    You want to use an instance of
    NSMutableArray,
    which will let you incrementally add elements to the array as you
    iterate with the for-loop:

    ...
    NSMutableArray *array = [NSMutableArray array];
    for (int i = 0; i < test.count; i++) { 
        NSDictionary *info = [test objectAtIndex:i]; 
        Animal *animal = [Animal animalObj:[info valueForKey:@"AnimalName"]  
                                  location:[info valueForKey:@"ScientificName"] 
                               description:[info valueForKey:@"FirstDesc"] 
                                     image:[UIImage imageNamed:@"cat.png"]];
        [array addObject:animal];
    }
    return array;
    

    Because NSMutableArray is a subclass of NSArray, there’s no need change the return type of your method.

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

Sidebar

Related Questions

I have a UITableViewController that contains a tableView. I want to set its scrollView
I have an UITableViewController , set up so that users can delete rows. This
I have a UIViewController that inherits from UITableViewContoller: @interface AllProductsViewController : UITableViewController And I
I have a UITableView that I want to edit inside of a UITableViewController. This
I have a UITableViewController that when loaded gets data from a web-service and stores
I have a UITableViewController which uses a NSMutableArray for it's datasource. The array is
I have a UITableViewController that uses didSelectRowAtIndexPath: to init a view controller with initWithNibName:
Right now I have an UITableViewController that displays a set of Artist objects sorted
I have a UITableViewController subclass that renders a list of pre-set categories and fetches
I have a UITableViewController that works in both portrait and landscape. From this controller

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.