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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:31:02+00:00 2026-06-10T10:31:02+00:00

Greetings StackOverflow. I have a scenario, in which I have a UITableView with a

  • 0

Greetings StackOverflow.

I have a scenario, in which I have a UITableView with a dynamic amount of sections.
This means that the table may have 1 section, 5 sections, 100 sections, whatever.

The problem is, each section is handled and displayed in a different manner.

Section 0, for example, contains say a list of purple cells, while section 1 contains yellow cells.
Thus, I need to be able to calculate the index that each section type will end up as.

By this, I mean, assuming the priority of the sections is as follows:
Magenta, Yellow, Green, White
Then when all sections are filled, they will be in that order, M=0, Y=1, G=2, W=3.
However, when one section is missing, say Yellow, the result is as follows:
M=0, Y=-1, G=1, W=3
Thereby removing yellow from the list, and bumping down the indices for the section.

I have already built something that accomplishes this for small section sizes by using tertiary statements, but as it defines each section type manually it quickly blows out of proportion:

// Here be some dragons.
// Each macro identifies a section 
#define SectionMagenta  (([self  shouldDisplaySection:0])?0:-1) // 1 tertiary statements
#define SectionYellow   (([self  shouldDisplaySection:1])?((SectionMagenta==-1)?0:1):-1) // 3 tertiary statements
#define SectionGreen    (([self  shouldDisplaySection:2])?((SectionMagenta==-1)?((SectionYellow==-1)?0:1):((SectionYellow==-1)?1:2)):-1) // 11 tertiary statements
#define SectionWhite    (([self  shouldDisplaySection:3])?((SectionMagenta==-1)?((SectionYellow==-1)?((SectionGreen==-1)?0:1):((SectionGreen==-1)?1:2)):((SectionYellow==-1)?((SectionGreen==-1)?1:2):((SectionGreen==-1)?2:3))):-1) // 63 tertiary statements

There is a pattern here. A very complex one, yes, but a pattern none the less.

My question to you all, is if you can simply this pattern into a small, probably recursive function, that I pass in the priority of the section, and it calculates the destination index.
OR
if you can create a much simpler method of achieving what I need.
For the latter, simply setting the amount of rows displayed to 0 is not sufficient, as the padding for the section is still existent.

I’ve provided a helper function–as can be seen in the copypasta code above-to check if a section should be displayed: [self shouldDisplaySection:n]
That may very well provide all you need.

  • 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-10T10:31:03+00:00Added an answer on June 10, 2026 at 10:31 am

    Sounds like you actually want to use an Ordered Dictionary and just push the values you’re wanting onto it, then read them off in order with the numeric indexes as your section order.

    A fairly good example of an ordered dictionary implemented in Obj-C is at http://cocoawithlove.com/2008/12/ordereddictionary-subclassing-cocoa.html

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

Sidebar

Related Questions

Greetings, stack overflow In my database, I already have one table, 'contacts' that contains
Greetings I may have imagined this but does anyone know if Last.fm previously used
Greetings StackOverflow community! For this new project I'm required to write a trigger which
Greetings to all! This is my first question here on stackoverflow. I have a
Greetings, I have a complicated scenario to handle. I have a wsdl file which
Greetings! I have a Repeater control that's using an XmlDataSource control. <asp:FormView id=myFormView runat=server
Greetings stackoverflow. I have been tinkering about with a SOAP client using PHP5's native
Greetings stackoverflow community! I am working on an Android game that uses Box2D for
Greetings all, I have posted this on the MSDN managed news groups as well
Greetings I have an ajax call which: Gets an xml file of posts Populates

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.