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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:02:33+00:00 2026-06-08T10:02:33+00:00

I have a viewController that displays the result of a query using a tableview).

  • 0

I have a viewController that displays the result of a query using a tableview).
By taping on a row a I push a the childView and I set a navigationBar that contains 2 buttons on the right (Previous/Next).
My question is :
How can I switch to the previous or next “childView” when I tap on previous or next button?
I would like to have also a transition effect while the view is switching?
Any 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-06-08T10:02:34+00:00Added an answer on June 8, 2026 at 10:02 am

    I had a view that contained a list of camps, and touching one takes users to the camp details. I wanted to allow the user to swipe left and right to move through the list of camps displaying the details of each. I wanted a visual animation that showed the swipe, and that the ‘Back’ button always referred to moving back up the navigation stack, ie, returning to the list.

    The first view that has the table with results is the only object that knows what “previous” and “next” mean, so they will be responsible for implementing the swipe action. Because we will be making changes to the “currently displayed” row/section in that view, while the view is not the current view, you will need to add vars/properties to track that.

    Because the navigation controller can already animate view changes, I let it do the majority of work. When moving “previous”, I create a new view with the previous entry details, insert it into the navigation stack (between the LIST view and the current DETAIL view), and do a popViewControllerAnimated which provides a visual effect and also unloads the details view just animated off.

    To move to the “next” camp details, I create a new view with the next entry details, add it onto the end of the navigation stack, it animates in, then I clean up the navigation stack by removing the details view that just animated off.

    So, in a nutshell:
    The details view will detect the swipe gestures and inform the parent.
    The parent determines the next/previous row that should be displayed.
    The parent replaces the current view with a new one, animating the replacement left/right to visually indicate the effect. The parent also updates the navigation stack to ensure that the “Back” button always acts as a pop to the LIST view, not to a previously shown DETAIL view.

    I can’t post all my code here, but below is the majority. Some specific GOTCHAS to watch out for:

    1. Manipulating the navigation stack can cause warning errors at runtime if you try to delete a VC while it is animating out. Therefore we wait until it is completely replaced, then remove it, by registering as the delegate for the navigation controller, and using the “didShowViewController” method to detect when it is safe to make changes. This complication is only needed when moving forward in the list, since in the “back” logic, the navigation controller cleans up itself after the popViewController.

    2. In order to use didShowViewController you must set a delegate. The delegate must not be a VC that may go away, otherwise you will get a crash. I only have the controlling LIST view set itself as a delegate.

    3. As you manipulate which row/section the user is viewing the details of, I also move the highlight (and scroll the table) on the hidden LIST view, so that when they eventually go “BACK” to it, the last viewed item is shown.

    When creating a DETAIL view, pass in the parent, define methods to let the parent know a swipe occurred, and register swipe recognizers on the DETAIL view, in the viewDidLoad method,

    Code in the LIST view (parent)

        -(NSString *) nameOfPreviousCampAndUpdateCurrents;
        {
            // pseudo code
            //  targetsection = srcSection
            //  targetrow = srcRow-1.
            // if targetrow < 0
            //   targetsection = srcSection - 1
            //   targetrow = last row of targetsection
            // if targetSection <  0
            //   return nil;
            //
            // return name at targetsection, targetrow
    
            NSInteger targetSection;
            NSInteger targetRow;
            NSString  *results = nil;
    
            targetSection = self.currentDetailViewSection;
            targetRow = self.currentDetailViewRow-1;
    
            if (targetRow < 0)
            {
                targetSection--;
                if (targetSection <0)
                {
                    return nil;
                }// end if
    
                NSInteger numberOfRowsInSection = [self tableView:self.myTable numberOfRowsInSection:targetSection];        
                targetRow = numberOfRowsInSection-1;        
            }// end if
    
            results = [self getCampNameInSection:targetSection atOffset:targetRow];
            self.currentDetailViewSection = targetSection;
            self.currentDetailViewRow = targetRow;
    
            return results;
    
        }
    
       - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
        {
            // Navigation logic may go here. Create and push another view controller.
    
            CampDetails *detailViewController = [[[CampDetails alloc] initWithNibName:nil bundle:nil] autorelease];
            detailViewController.campName = [self getCampNameInSection:indexPath.section atOffset:indexPath.row];
            detailViewController.campID = [self getCampIDForSection:indexPath.section atOffset:indexPath.row];
            detailViewController.parent = self;
    
            self.currentDetailViewSection = indexPath.section;
            self.currentDetailViewRow = indexPath.row;
    
            // ...
            // Pass the selected object to the new view controller.
            [[self navigationController] pushViewController:detailViewController animated:YES];
            //[detailViewController release];
    
        }
    
        -(void) viewDidLoad;
        {
            // The ROOT view controller should do this.
            if ([[self.navigationController viewControllers] count] == 1)
            {
                self.navigationController.delegate = self;        
            }// end if
        }
    
        -(void) moveToNextCamp;
        {
            NSString *nextCamp = [self nameOfNextCampAndUpdateCurrents];
    
            if (nextCamp == nil)
            {
                UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Warning"
                                                                message:@"You are already at the last item in the list of camps."
                                                               delegate:self
                                                      cancelButtonTitle:@"OK"
                                                      otherButtonTitles:nil];
                [alert show];
                [alert release];
    
                return;
            }// end if
    
            CampDetails *detailViewController = [[[CampDetails alloc] initWithNibName:nil bundle:nil]autorelease];
            detailViewController.campName = nextCamp;
            detailViewController.campID = [self getCampIDForSection:self.currentDetailViewSection atOffset:self.currentDetailViewRow];
            detailViewController.parent = self;
    
            // do the animation to the right
            [self.navigationController pushViewController:detailViewController animated:YES];
    
    
        //    remove the previous controller so that popping the current one takes us "up"
        //    WHILE THE FOLLOWING CODE DOES WORK, it also results in a runtime warning.  
        //    so instead, we tinker with the controller stack only when it's safe (see below)
        //    NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
        //    [viewControllers removeObjectAtIndex:1];
        //    [self.navigationController setViewControllers:viewControllers animated:NO];
        //    
    
            // clean up the stack AFTER the child is shown.  
            self.userJustSwiped = YES;
    
            [self updateTableHighlightAndScrollPosition];
    
    
        }
        -(void) moveToPreviousCamp;
        {
            NSString *previousCamp = [self nameOfPreviousCampAndUpdateCurrents];
    
            if (previousCamp == nil)
            {
                UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"Warning"
                                                                message:@"You are already at the first item in the list of camps."
                                                               delegate:self
                                                      cancelButtonTitle:@"OK"
                                                      otherButtonTitles:nil];
                [alert show];
                [alert release];
    
                return;
            }// end if
    
            CampDetails *detailViewController = [[[CampDetails alloc] initWithNibName:nil bundle:nil]autorelease];
            detailViewController.campName = previousCamp;
            detailViewController.campID = [self getCampIDForSection:self.currentDetailViewSection atOffset:self.currentDetailViewRow];
            detailViewController.parent = self;
    
            // add the controller so that popping the current one takes us there    
            NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];    
            NSInteger lastNavStackEntryIndex =  [viewControllers count]-1;    
            [viewControllers insertObject:detailViewController atIndex:lastNavStackEntryIndex];
            [self.navigationController setViewControllers:viewControllers animated:NO];
    
            // do the animation (which also releases the previously current vc)
            [self.navigationController popViewControllerAnimated:YES];
    
            [self updateTableHighlightAndScrollPosition];
    
        }
    
        - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
        {
            // IF we just swiped to a details view, do some clean up
            if (self.userJustSwiped)
            {
                self.userJustSwiped = NO;
                // clean up the stack AFTER the child is shown.  remove the previous controller so that popping the current one takes us "up"
                NSMutableArray *viewControllersArray = [NSMutableArray arrayWithArray:navigationController.viewControllers];
    
                NSInteger lastNavStackEntryIndex =  [viewControllersArray count] - 1;
    
                [viewControllersArray removeObjectAtIndex:lastNavStackEntryIndex-1];
                [navigationController setViewControllers:viewControllersArray animated:NO];        
    
            }// end if
    
    
    
        }
    
        -(void) userSwipedLeftOnChild;
        {
            [self moveToNextCamp];
        }
    
        -(void) userSwipedRightOnChild;
        {
            [self moveToPreviousCamp];
        }
    

    Code in the DETAILS view (child):

    -(void) leftSwipe:(UIGestureRecognizer*)recognizer;
    {
        [self.parent userSwipedLeftOnChild];
    }
    -(void) rightSwipe:(UIGestureRecognizer*)recognizer;
    {
        [self.parent userSwipedRightOnChild];
    }
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        // add swipe recognizers
        UISwipeGestureRecognizer *leftSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(leftSwipe:)];
        [leftSwipe setDirection:UISwipeGestureRecognizerDirectionLeft];
        [self.view addGestureRecognizer:leftSwipe];
        [leftSwipe release];
    
    
        UISwipeGestureRecognizer *rightSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(rightSwipe:) ];  
        [rightSwipe setDirection:UISwipeGestureRecognizerDirectionRight];
        [self.view addGestureRecognizer:rightSwipe];
        [rightSwipe release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a viewController that has a tableView and a custom loading UIView that
I have a navigation controller that displays viewcontroller A. There is a right button
I have two ViewController. The first contains and displays an array with values. The
I have a view controller based app that contains several views that I display/hide
I have a ViewController that includes its own .nib file, I am wanting to
I have a ViewController that has its own NIB. I would like to embed
I have a viewController that autorotates just fine, The problem is that is I
i have more viewcontroller that start from rootviewcontroller. So for example i start with
I want to have a ViewController that has a table view on the top
I have created two viewController classes such that one is superclass of another.i have

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.