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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:55:04+00:00 2026-05-29T14:55:04+00:00

I would like to break my table view into sections. I would like to

  • 0

I would like to break my table view into sections. I would like to see an example, of a table view broken into 3 sections, and then me being able to choose the index where the sections begin.

So if I have an array of objects, and they populate a table view. I would like to choose the titles of the sections and where the sections begin (so for row 1-13 would be section 1, 13-30 would be section 2, etc…).

I have this so far:

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

    if (ingredientListChoice == 1) { 
        return 3;

    }

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section 
{
    if (ingredientListChoice == 1) {
    return @"Section Title";
    }
}

Please let me know if you can show me an example of what I am getting at. Thank you.

  • 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-29T14:55:05+00:00Added an answer on May 29, 2026 at 2:55 pm

    Here’s a rough way to do it. Basically you’ll need to return the correct size of each section from tableView:numberOfRowsInSection: and then set the correct content in your table cell by adding an offset to the row index position when pulling the content from your data array in tableView:cellForRowAtIndexPath:.

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return 3;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        switch (section) {
            case 0: return 13; break;
            case 1: return 17; break;
    
            etc...
        }
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
    {
        cell = [tableView dequeueReusableCellWithIdentifier:@"MyCell"];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
    
        int offset = 0;
        switch (section) {
            case 0: offset=0; break;
            case 1: offset=13; break;
            case 2: offset=30; break;
    
            etc...
        }
    
        int arrayRow = indexPath.row + offset;
        cell.textLabel.text = [myArray objectAtIndex:arrayRow];
    
        return cell;
    }
    

    A cleaner way might be to store the sizes of your sections in an array you store as a property (which you would perhaps set in viewDidLoad) and then numberOfRowsInSection and cellForRowAtIndexPath could read the necessary value(s) from that array, so that if in the future you needed to change the sizes of your sections you’d only have to update one place.

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

Sidebar

Related Questions

I would like to break a long line of text assigned to the standard
original column is like: 0.45::rafas::4.0::0.0::0.9 0.35::rasaf::4.0::110.0::1.0 and i would like to break the string
I would like Visual Studio to break when a handled exception happens (i.e. I
Would like to be able to set colors of headings and such, different font
I am usually using table to do layouting. But I would like to try
I have managed to display data in one column table, but would like to
Would like to get a list of advantages and disadvantages of using Stored Procedures.
Would like to create a strong password in C++. Any suggestions? I assume it
Would like to know what a programmer should know to become a good at
Would like to make anapplication in Java that will not automatically parse parameters used

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.