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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:20:05+00:00 2026-05-29T11:20:05+00:00

I am writing an iPhone application and I have a table view that is

  • 0

I am writing an iPhone application and I have a table view that is populated by information I feed it from txt files. I would like to group the tables (so like by name for contacts), however I would like to choose which fields go in which grouping.

For instance, for my app, I want to group ingredients by type (so dairy products, produce, etc…) and have the corresponding ingredients appear there. How would I do that? I have this code currently for my table view:

NSString *wellBalancedIngredientFileContents = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Well Balanced Ingredients" ofType:@"txt"] encoding:NSUTF8StringEncoding error:NULL];


wellBalancedIngredients = [wellBalancedIngredientFileContents componentsSeparatedByString:@"(penguins)"];

wellBalancedIngredients (as one of the arrays) is an array that will contain all of the “well balanced ingredients”. I have 3 other arrays that I also populate the tableview with depending on user choice.

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{


    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{



    if (ingredientListChoice == 1) { 
        return [self.wellBalancedIngredients count];

    }
    else if (ingredientListChoice == 2) {
        return [self.meatIngredients count];

    }
    else if (ingredientListChoice == 3) {
        return [self.vegetarianIngredients count];

    }
    else {
        return [self.veganIngredients count];

    }

}

- (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];
    }


    if (ingredientListChoice == 1) {
        cell.textLabel.text = [self.wellBalancedIngredients objectAtIndex:indexPath.row];
    }
    else if (ingredientListChoice == 2) {
        cell.textLabel.text = [self.meatIngredients objectAtIndex:indexPath.row];
    }
    else if (ingredientListChoice == 3) {
        cell.textLabel.text = [self.vegetarianIngredients objectAtIndex:indexPath.row];
    }
    else {
        cell.textLabel.text = [self.veganIngredients objectAtIndex:indexPath.row];
    }
    return cell; 
    // Configure the cell...

}

How do I add to this code to add the grouping into sections and then being able to have custom headings and me populating each section according to my chosen preference. Thank you for your help.

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

    First, you should return the number of sections you want in the table:

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

    Then, for the title of each section you can use:

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
    {
        return @"Section Title";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing an iPhone application that needs to record audio from the built-in
I am writing the iPhone application and I would like to ask about the
I have a children's iPhone application that I am writing and I need to
I'm writing an iPhone application that needs to send small bits of information (two
In my Iphone application I am trying to navigate from one table view controller
I'm currently writing an iPhone application that uses a UITabBarController with more than 5
I'm writing an iPhone application and I find that there are three controllers in
So I'm looking at writing an iPhone application that shows things on a map.
Hey folks - I'm writing a pretty simple iPhone application. The data comes from
I have an Objective C - iPhone Application I am writing, and I think

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.