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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:06:51+00:00 2026-05-24T01:06:51+00:00

So, i have 3 section like i said in my previous question, A, B,

  • 0

So, i have 3 section like i said in my previous question, “A”, “B”, “C”, for example.

This is the code i’m using:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    switch (indexPath.row) 
    {
        case 0:
            [self.navigationController pushViewController:[[[FirstViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
            break;

        case 1:

            [self.navigationController pushViewController:[[[SecondViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
            break;
    etc..       
 }
}

This is my problem: in “A” i have 6 elements. If i use the switch from 0 to 5, it pushes out the right View Controllers. But when i have to push out the View Controllers for the “B” section, that contains another 9 elements, i go ahead with the counter (so case 7,8 etc),it starts again to show the controllers from the begin (it pushes out again FirstViewController” etc). Same story for “C” section. How to solve this?

I’m hating grouped tables, damn.

Edit: new code, looping

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    switch (indexPath.section) 
    {
        case 0:


            switch (indexPath.row) {
                case 0:

                    [self.navigationController pushViewController:[[[FirstViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
                break;

                case 1:

                    [self.navigationController pushViewController:[[[SecondViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
                break;
        }

        case 1:
            switch (indexPath.row) {
                case 0:
            [self.navigationController pushViewController:[[[ThirdViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
            break;
        case 1:
            [self.navigationController pushViewController:[[[FourthViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
            break;

        case 2:
            [self.navigationController pushViewController:[[[FifthViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
            break;

            }
        case 2:
            switch (indexPath.row) {
                case 0:
            [self.navigationController pushViewController:[[[SixthViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
            break;

        case 1:
            [self.navigationController pushViewController:[[[SeventhViewController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES];
            break;



            }
    }
}

I’ve obviously cut the code, too long otherwise.

Edit 2:

Worked! Sergio’s answer was right, but i put an if (indexPath.section == 0) instead of switch (indexPath.section){}

  • 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-24T01:06:52+00:00Added an answer on May 24, 2026 at 1:06 am

    The NSIndexPath indexPath argument that didSelectRowAtIndexPath is passed has two properties: row and section. If you properly use the section info, you will be able to distinguish among the three sections you have.

    E.g. (this is ugly, but it will work):

     - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        switch (indexPath.section) 
        {
            case 0:
            switch (indexPath.row) 
            {
                case 0:
                ...
                break;
                ...
            }
            break;
    
            case 1:
    
            switch (indexPath.row) 
            {
                case 0:
                ...
                break;
                ...
            }
            break;
    
            etc...
       }
    }
    

    A better solution, IMO, would be encoding in your data source the sub table type associated to each element, so that you do not need a big switch and each cell already “knows” what kind of sub table it should open. You can inspect the Class type (look also at this question).

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

Sidebar

Related Questions

I have a section of code that can be summarised as follows; void MyFunc()
I have html output in paging section like this; <p>&nbsp;<strong class=active>1</strong>&nbsp;<a href=http://localhost/project/report_nc/search_now/1>2</a>&nbsp;<a href=http://localhost/project/report_nc/search_now/2>3</a>&nbsp;<a href=http://localhost/project/report_nc/search_now/1>Next
I have an XML file which has many section like the one below: <Operations>
I have a section: \section{Introduction} \label{sec:introduction} I'd like a link to the section where
I have SEF urls like /sitename/section/12-news-title and number 12 is id of the news.
On a blog detail page, I have a tags section. The html looks like:
My XML is like: <root> <section name=blah> <item name=asdf>2222</item> </section> </root> I will have
I have a section of makefile that has this sort of structure: bob: ifdef
I have a section of code that is being used to determine if a
I have a section like $myresult .= '<tbody>'; /*start printing the table wth feature

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.