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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:20:11+00:00 2026-05-27T09:20:11+00:00

I create the following data on viewDidLoad: – (void)viewDidLoad { [super viewDidLoad]; food =

  • 0

I create the following data on viewDidLoad:

- (void)viewDidLoad {
    [super viewDidLoad];

    food = [[NSMutableArray alloc] initWithObjects: @"Harvey's",@"McCormicks",@"Subway",nil];
    gifts = [[NSMutableArray alloc] initWithObjects:@"The gift Shop",@"Lilo Gifts",@"Prezzies for All", nil];
    services = [[NSMutableArray alloc] initWithObjects:@"Hair Snippers",@"Laundro-mat",@"Accountants",@"Shoe fitters", nil];
    hotel = [[NSMutableArray alloc] initWithObjects:@"Hotel Paradiso",@"Dick & Doms B&B",@"Super Hotel",@"Castle B&B", nil];
    pubs = [[NSMutableArray alloc] initWithObjects:@"The Snuggly Duckling",@"Beer's Arms",@"Merlins Beard", @"Cheers", nil];


}

Here are my data source methods:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 5;
}

- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return NSLocalizedString(@"Food & Restaraunts", nil);
        case 1:
            return NSLocalizedString(@"Shopping/ Gifts", nil);
        case 2:
            return NSLocalizedString(@"Services", nil);
        case 3:
            return NSLocalizedString(@"Hotels / B&B's", nil);
        case 4:
            return NSLocalizedString(@"Pubs",nil);

        default:
            return nil;
    }



}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    switch (section) {
        case 0:
            return 3;
        case 1:
            return 3;
        case 2:
            return 4;
        case 3:
            return 4;
        case 4:
            return 4;
        //default:
        //  return 1;

    }



}


// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    //mine  

        switch (indexPath.section) {
    case 0:
        [[ cell textLabel]
         setText:[food objectAtIndex:indexPath.row]];
        break;
    case 1:
        [[ cell textLabel]
         setText:[gifts objectAtIndex:indexPath.row]];
        break;
    case 2:
        [[ cell textLabel]
        setText:[services objectAtIndex:indexPath.row]];
        break;
    case 3:
        [[ cell textLabel]
        setText:[hotel objectAtIndex:indexPath.row]];
        break;
    case 4:
        [[ cell textLabel]
        setText:[pubs objectAtIndex:indexPath.row]];
        break;

    } 

    return cell;
}

}

What its actually doing is displaying the first 10 lines correctly then repeating the list again, if I add more lines to the first couple of sections it repeats earlier up the table.. I’ve cleared the cache etc but nothing works.

  • 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-27T09:20:11+00:00Added an answer on May 27, 2026 at 9:20 am

    That’s because you set contents of your reusable cells only once.

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];}
    //mine  
    
        switch (indexPath.section) {
    case 0:
        [[ cell textLabel]
         setText:[food objectAtIndex:indexPath.row]];
        break;
    case 1:
        [[ cell textLabel]
         setText:[gifts objectAtIndex:indexPath.row]];
        break;
    case 2:
        [[ cell textLabel]
        setText:[services objectAtIndex:indexPath.row]];
        break;
    case 3:
        [[ cell textLabel]
        setText:[hotel objectAtIndex:indexPath.row]];
        break;
    case 4:
        [[ cell textLabel]
        setText:[pubs objectAtIndex:indexPath.row]];
        break;
    
    
    
    return cell;}
    

    I am not good at post formatting. You should set content of your cell after taking it from “reuse stack”.

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

Sidebar

Related Questions

I create the following class: class Image(object): def __init__(self, extension, data, urls=None, user_data=None): self._extension
I have the following table and data in SQL Server 2005: create table LogEntries
Trying to create a list to return some JSON data to a view. Following
If I have a requirement to create a data structure that has the following
Based on the following data structure. CREATE TABLE [Parent] ( Id INT, Name nvarchar(100)
I need to create the following data structure: userid, onlinetime, offlinetime I need the
Given the following data table definitions in SQLite Version 3.7.5: CREATE TABLE [Books] (
I have the following data and am trying to create a barplot in R
I'm trying to create the following data structure in Qt 4.5 in C++: QMap<int,
I am attempting to dynamically create the following using data from an array <li><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.