Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Select the second sub view controller #22

Open
johannwilfling opened this issue Sep 14, 2014 · 1 comment
Open

Select the second sub view controller #22

johannwilfling opened this issue Sep 14, 2014 · 1 comment

Comments

@johannwilfling
Copy link

What's the recommended way to make the second sub view controller selected after the AXStretchableHeaderTabViewController has loaded?

@CZyMfnIPC
Copy link

I added some additional methods to "AXStretchableHeaderTabViewController.m" to add this feature.

-(void)setCurrentViewControllerToIndex:(int)index
{
    if(_viewControllers.count > index)
    {
        [_tabBar setSelectedItem:_tabBar.items[index]];
        [self didSelectTabBarItemAtIndex:index];

        [self layoutSubViewControllerToSelectedViewController:self.selectedViewController];
    }
}

-(void)setCurrentViewControllerToTabName:(NSString *)tabName
{
    //search through each tab bar button to find out which one matches the requested page
    [_tabBar.items enumerateObjectsUsingBlock:^(UIBarButtonItem *barButton, NSUInteger idx, BOOL *stop)
    {
        //if the button matches our text
        if([barButton.title isEqualToString:tabName])
        {
            //get the index of this button and set the view controller based on this index
            int indexOfButton = (int)[_tabBar.items indexOfObject:barButton];
            [self setCurrentViewControllerToIndex:indexOfButton];

            //return out of the enumeration, we only expect to find one match
            return;
        }
    }];
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants