Xlpagertabstrip: How to go to a specific child view controller

Created on 3 Feb 2016  Â·  16Comments  Â·  Source: xmartlabs/XLPagerTabStrip

Hello,

I have 5 child viewcontroller. When in one of them I go to another view. From that view I want to be able to go back to that child viewcontroller (the one that I came from)

Do you know how I can do to to go to a specific viewcontroller?

Thank you for your attention.

All the best.

question

Most helpful comment

@adisain . you should put _moveToViewController(at: )_ method in _viewDidAppear(_ animated: Bool) {}_ . hope helpful

All 16 comments

Have you seen this?
https://github.com/xmartlabs/XLPagerTabStrip#how-to-change-the-visible-child-view-controller-programmatically

I have the same question. I have seen the link you give, thanks. But I am not sure how and where to call the specific function.

@aferrerb should work regardless if the view is visible or not.

@mtnbarreto Hi, thanks. That is not the issue I have. I want to go to a specific child view controller, say, the 3rd in the array. So where do I put the line
func moveToViewController(viewController: UIViewController);
I know which View controller to go to, I am just not able to see where I am able to condition it.
Thanks

moveToViewController(viewController: UIViewController) belongs to pager controller. You can invoke it at any time.

self.moveToViewControllerAtIndex(3, animated: true)

super.viewDidLoad()
moveToViewControllerAtIndex(3, animated: false)  // current class type extends from a pager type

makes your pager show the 3rd view controller when presenting it.

if the pager controller is already visible, it may be better to pass true as animated parameter or not pass any animated parameter since by default is true.
moveToViewControllerAtIndex(3, animated: true)
or
moveToViewControllerAtIndex(3)

i'm not understood what you mean by: "I am just not able to see where I am able to condition it."

Not sure if I understand ....

Considering the pager view is not released you don't need to do anything else. current index does not change since the view controller was not released.

In case the pager view was released you need to save the urrent pager index (currentIndex readonly property) befor transitioning to new view controller and then when instantiating the pager controller again invoke moveToIndex using the index you had saved before made the transition to the new controller.

I am sorry, I am probably not explaining this very well, apologies. Let me try again.
There is an initialViewController that loads the children view controller. Say I go to the 3rd of the children view controller. In this View I can then Open another View Controller and from this one I want to go BACK to the 3rd View controller.
I was trying to use the functions provided, but I get an error: Property 'moveToViewControllerAtIndex' not found on object of type 'XLPagerTabStripViewController' ... But it is there and I am importing it.
So basically, I want to be able to press BACK from a view in the app and dictate which child to show ... does this make more sense?
Thanks very much!

OK, I have done put the code, and it compiles. But it actually does not move to that View Controller. I have put the call in the viewDidLoad within InitialViewController:
if ([global.discernmentId isEqualToString:@"Gospel"]){
[thisView moveToViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"gospelViewController"]];
}
Is this how it can be used?

Thanks very much!

OK, so putting the above code doesn't actually do anything ... am I missing something?
Thanks very much

Hi Martin,
I see what you mean. I tried the following:I created a global variable in the AppDelegate. It would be set to different values depending on the View Controller the user went to.
I then tried to evaluate it in the following function-(void)pagerTabStripViewControllerInit{    AppDelegate *global;    if ([global.discernmentId isEqualToString:@"Gospel"]) _currentIndex = 1;     else _currentIndex = 0;    _delegate = self;    _dataSource = self;    _lastContentOffset = 0.0f;    _isElasticIndicatorLimit = NO;    _skipIntermediateViewControllers = YES;    _isProgressiveIndicator = NO;}
But the value in global.discernmentID is not retained, by the time it gets to this function is set to null. 
I don't know how to use the _currentIndex OUTSIDE of this class to set it to a specific value.
Would you be able to help? 
Thanks a lot!Ana

On Wednesday, 3 February 2016, 22:54, Martin Barreto <[email protected]> wrote:

Not sure if y understand ....Considering the pager view is not released you don't need to do anything else. current index does not change since the view controller was not released.In case the pager view was released you need to save the urrent pager index (currentIndex readonly property) befor transitioning to new view controller and then when instantiating the pager controller again invoke moveToIndex using the index you had saved before made the transition to the new controller.—
Reply to this email directly or view it on GitHub.

Hi Martin,
I have now been able to solve the issue I was having. I now use the "declaration" of the AppDelegate that you have and it all works ...
Thank very much. It was the current Index that gave me the clue. 
Best regardsAna

On Wednesday, 3 February 2016, 22:54, Martin Barreto <[email protected]> wrote:

Not sure if y understand ....Considering the pager view is not released you don't need to do anything else. current index does not change since the view controller was not released.In case the pager view was released you need to save the urrent pager index (currentIndex readonly property) befor transitioning to new view controller and then when instantiating the pager controller again invoke moveToIndex using the index you had saved before made the transition to the new controller.—
Reply to this email directly or view it on GitHub.

@aferrerb great!
Sorry for being out for a while.

Regards,
Martin

No worries Martin, it is difficult to help at the best of times, even harder in writing and to make it worse we are probably in completely different parts of the world.
Thanks again for your help!

Did anyone here not receiving Unbalanced calls to begin/end appearance transitions for warning in the console?

Hi Aferrerb,

Can you please clarify how you solved the problem. I am having the same challenges. Thanks @aferrerb

@adisain . you should put _moveToViewController(at: )_ method in _viewDidAppear(_ animated: Bool) {}_ . hope helpful

Was this page helpful?
0 / 5 - 0 ratings