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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:47:53+00:00 2026-06-12T02:47:53+00:00

I have a tableview that I am populating with JSON , but it is

  • 0

I have a tableview that I am populating with JSON, but it is doubling the values that I have. I only have 2 objects, but it is putting 4 in the tableview. Can someone tell me what I am doing wrong and why I am listing 4 objects when there are only 2? I have checked the count and the data model and they both only show 2 items.

Here is my code:

    //
//  RootBeerTableViewController.m
//  BaseApp
//
//  Created by Blaine Anderson on 9/27/12.
//  Copyright (c) 2012 UIEvolution, Inc. All rights reserved.
//

#import "RootBeerTableViewController.h"
#import "GlobalData.h"

@interface RootBeerTableViewController ()



@end

@implementation RootBeerTableViewController

@synthesize rootList;

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

   UITableView *tableView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame] style:UITableViewStylePlain];

    tableView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;

    tableView.delegate = self;

    tableView.dataSource = self;

    [tableView reloadData];



    self.view = tableView;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    rootList =[[GlobalData sharedData].mRootBeers getRootBeers];
     NSLog(@"RootList: %@", rootList);
    // Return the number of sections.
    NSLog(@"RootList count: %i", rootList.count);
    return rootList.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
        // Return the number of sections.
     NSLog(@"RootList row count: %i", rootList.count);
    return rootList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    rootList =[[GlobalData sharedData].mRootBeers rootBeerList];
     NSLog(@"RootList Cell: %@", rootList);
    RootBeers* mRootBeer = [rootList objectAtIndex:indexPath.row];


    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if(cell == nil){
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle  reuseIdentifier:@"Cell"]; 
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    NSLog(@"Cell Name: %@", mRootBeer.name);
       // Configure the cell...
    cell.textLabel.text = mRootBeer.name; 
    cell.detailTextLabel.text = mRootBeer.brewer; 



    return cell;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [[GlobalData sharedData].mViewManager pushView:DETAILVIEW animated:YES]; 



}

@end
  • 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-12T02:47:54+00:00Added an answer on June 12, 2026 at 2:47 am

    I believe this is why…

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    rootList =[[GlobalData sharedData].mRootBeers getRootBeers];
     NSLog(@"RootList: %@", rootList);
    // Return the number of sections.
    NSLog(@"RootList count: %i", rootList.count);
    return rootList.count;
    }
    

    change it to this.

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    return 1;
    }
    

    You are adding a section for each object in rootList, and then adding all of rootlist in each section. So returning only one section is easiest.

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

Sidebar

Related Questions

I have a tableview that occupies only the bottom third of my view. I
I have a tableview that is blank by default. User can add cells to
I have a TableView that builds and draws ok, but then crashes on scrolling
If I have a tableview that has say 3 levels that the user can
I have a tableView that present a list of Books, each of the table
I have a tableView that's loosely based on the DetailViewController in ye olde SQLiteBooks.
I have created an tableview that shows RSSS. I check for internet connection then
I have a Tableview on AppDelegate That calls a SecondView (dvController) when DidSelectRowAtIndexPath using:
I have a controller that contains a tableView that spawns another controller modally to
I have 5 cells in a tableview that are all custom. Meaning, I've created

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.