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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:19:11+00:00 2026-05-24T13:19:11+00:00

This is somewhat long-winded, but I think better to be clear. I can’t seem

  • 0

This is somewhat long-winded, but I think better to be clear. I can’t seem to find the definitive way to do this, and the problem is subtle (I think).

I have an application whose GUI hierarchy looks something like:

  • Main List (has a custom TableCell and height)
    • Sub List (for a selected Main List item)
      • Sub List Info (on a selected Sub List item)
        • Further info
    • Settings (for a selected Main List item)
      • Settings Info (on a selected Settings item)
        • Further info

Once a main list item is selected, the user is able to swap between Sub List and Settings, each of which have their own GUI sub-hierarchy. The switch is made using a toolbar.

I’ve tried several approaches and nothing seems to work exactly right.

First try (inspired by other questions here)

  • UINavigationController
    • UITableViewControllerBase (loaded from nib)
      • TableViewController1 (loaded programmatically on didSelectRowAtIndexPath)
      • TableViewController2 (can be swapped from TableViewController1)

I pass a reference to the rootViewController through as the various objects are created, then use that to do the switch.

[rootViewController switchViews]

In rootViewController.switchViews():

[TableViewController2 alloc] init];
[TableViewController1 removeFromSuperview];
[self.view insertSubview:TableViewController2.view atIndex:0]
. . .

Basically, rootViewController manages the switch. This works for the switch, but when I navigate back through the hierarchy to the Main List, it doesn’t initialize the table cells properly.

In cellForRowAtIndexPath:

static NSString *CellId = @"CellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIDentifier:CellId];
if (cell == nil)
{
  ... (this does not get called)
}

because the code in the brackets doesn’t get called, the table view looks “generic”, that is, the custom cell is not used. While this might be an unrelated error, the whole approach here didn’t seem right to me. My understanding is that the active view controller should be handling the switch. So I tried something different . . .

Second try (inspired by Beginning iPhone Programming book):

  • UINavigationController
    • UITableViewControllerBase (loaded from nib)
      • UIViewControllerParent (loaded programmatically on didSelectRowAtIndexPath)
        • TableViewController1 (loaded programmatically on parent’s loadView)
        • TableViewController2 (can be swapped from TableViewController1)

Here we’re enclosing both the nested table views in a controller parent, and letting the parent do all the work.

In loadView() of parent:

TableViewController1 *tvc1 = [[UITableViewController alloc] init];
self.tableViewController1 = tvc1;
[self.view insertSubview:tableViewController1.view atIndex:0];
[tvc1 release];

The issue here is that tableViewController1, although inited, does not have a valid view at the time when it’s being inserted. So the loadView function gets called again and again . . . I also tried putting this code in viewDidLoad, same problem.

I read the example code TheElements from the iOS developer site, and was originally going to go that route. The problem is that after the user switches views in my application, there’s more screens that he can drill down into. I want all those screens to be part of the application’s hierarchy (so that we can go back to the Main List when we want to). While TheElements illustrates a switch, it just switches views in a single UIViewController – I need to be able to drill down after the switch to new screens and have all those screens be a part of the UINavigationViewController’s hierarchy, for navigation purposes.

I’m new to all this so it’s possible I’m thinking of things in the wrong way. Hence the question. I’m sure this design is somewhat common, so even though there are undoubtedly many ways to do it, I’m looking for the best practice. The key thing here is that after the switch is made, the user should be able to navigate further down in the UINavigationViewController’s hierarchy, and be able to navigate back up. That requires loading multiple UIViewControllers. I believe.

Many thanks for the time (and apologies for the long post).

  • 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-24T13:19:11+00:00Added an answer on May 24, 2026 at 1:19 pm

    So, if I understand your question correctly, you want to switch between two view controllers at the top of a navigation controller’s stack. Why don’t you just let the navigation controller do the work and use setViewControllers:animated:, replacing just the last view controller in the existing array.

    Example, with an additional flip animation (in SubListViewController):

    - (void)switchToSettings:(id)sender
    {
        [UIView transitionWithView:self.navigationController.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft animations:^ {
            SettingsViewController *settingsVC = [[[SettingsViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
            settingsVC.mainListItem = self.mainListItem;
            NSMutableArray *mutableViewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
            [mutableViewControllers removeLastObject];
            [mutableViewControllers addObject:settingsVC];
            [self.navigationController setViewControllers:mutableViewControllers animated:NO];
        } completion:^(BOOL finished) {}];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this is somewhat subjective, but I can't find an honest answer anywhere.
This is a somewhat long question, but I hope I can express it clearly.
This is not 100% programming related. But I think this is somewhat useful because
Is there a standard way to do this? I realize this can be somewhat
somewhat related to: libxml2 from java yes, this question is rather long-winded - sorry.
This is somewhat similiar to this : pthread function from a class But the
This is somewhat related to the question posed in this question but I'm trying
I know this sounds somewhat counterintuitive, but let me explain what I am trying
This is the problem I ran into long time ago. I thought I may
I think I've just been looking at this too long. I have some data

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.