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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:40:59+00:00 2026-06-01T02:40:59+00:00

I have a UITableView which I want to populate with details from an array

  • 0

I have a UITableView which I want to populate with details from an array of objects. The tableview shows the same item on every line (the correct number of lines though!) I know this must be an easy one – but I can’t see where I’ve gone wrong:

Code snippet of view that initializes the table data:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender

{

    if([segue.identifier isEqualToString:@"Show Tank List"])

    {

        NSURL *myUrl = [[NSURL alloc]initWithString:@"http://localhost/~stephen-hill9/index.php"];
        NSData *data = [[NSData alloc] initWithContentsOfURL:myUrl];
        NSError *error;
        NSArray *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
        int i;
        NSMutableArray *tanksList;
        tank *thisTank = [[tank alloc] init];
        tanksList = [[NSMutableArray alloc] init];
        for (i=0; i<json.count; i++) {
            NSDictionary *bodyDictionary = [json objectAtIndex:i];
            thisTank.tankNumber = [bodyDictionary objectForKey:@"ID"];
            thisTank.tankProduct = [bodyDictionary objectForKey:@"Product_Desc"];
            thisTank.tankPumpableVolume = [bodyDictionary objectForKey:@"Pumpable"];
            [tanksList addObject:thisTank];
        }
        [segue.destinationViewController setTanks:tanksList];
    }
}

…and the code that loads the table in the next view…

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;//keep this section in case we do need to add sections in the future.
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self.tanks count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Tank List Table Cell";
    UITableViewCell *cell = [self.tankTableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithFrame:CGRectZero];
    }
    tank *thisTank = [self.tanks objectAtIndex:indexPath.row];
    cell.textLabel.text = thisTank.tankNumber;
    return cell;
}
  • 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-01T02:41:00+00:00Added an answer on June 1, 2026 at 2:41 am

    Move this:

    tank *thisTank = [[tank alloc] init]; 
    

    Inside your for loop. You’re updating the same object over and over again.

    Also, you’re initialising the cell wrong – use the designated initialiser, and pass the reuse identifier in, otherwise you will create new cells all the time:

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    

    And you really should follow objective-c naming conventions. Classes begin with upper case letters, everything else begins with a lower case letter. It makes your code much easier to read, for other people anyway.

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

Sidebar

Related Questions

I have an array of objects which populate a UITableView . When a user
I have a UITableView which shows some information. The informations are from a XMLFile.
I have a UITableView which is populated by an array, I have a button
I have a custom UITableView header which I want to be able to scroll
I have a UITableView which I fill with CoreData fetched results. I want to
I have a table view which i want to populate with the results (XML)
I have a UITableView which contains x amount of cells. However, I want to
I have a UITableView (on a UIViewController) on which I want to ad an
I have a UITableview with a UISearchBar, which contain Japanese words, and I want
I have a UITableView which loads its data from the web. It takes a

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.